| 1 | Index: meta.py | 
|---|
| 2 | =================================================================== | 
|---|
| 3 | --- meta.py     (revision 321) | 
|---|
| 4 | +++ meta.py     (working copy) | 
|---|
| 5 | @@ -1268,12 +1268,22 @@ | 
|---|
| 6 | order_by = ", ".join(order_by) | 
|---|
| 7 |  | 
|---|
| 8 | # LIMIT and OFFSET clauses | 
|---|
| 9 | -    if kwargs.get('limit') is not None: | 
|---|
| 10 | -        limit_sql = " LIMIT %s " % kwargs['limit'] | 
|---|
| 11 | -        if kwargs.get('offset') is not None and kwargs['offset'] != 0: | 
|---|
| 12 | -            limit_sql += "OFFSET %s " % kwargs['offset'] | 
|---|
| 13 | +    #gheorghe: | 
|---|
| 14 | +    from django.conf.settings import DATABASE_ENGINE | 
|---|
| 15 | +    limit_sql = "" | 
|---|
| 16 | +    if DATABASE_ENGINE=="ado_mssql": | 
|---|
| 17 | +        if kwargs.get('limit') is not None: | 
|---|
| 18 | +            select[0] = 'TOP %s %s' % (kwargs['limit'], select[0]) | 
|---|
| 19 | +            if kwargs.get('offset') is not None and kwargs['offset'] != 0: | 
|---|
| 20 | +                #the problem is if PK is not ID and also if user adds GROUP BY, HAVING etc (can a user do that?), | 
|---|
| 21 | +                #those should be added to the subquery too and they can't be | 
|---|
| 22 | +                #or at least I don't know how | 
|---|
| 23 | +                where.append("id NOT IN (SELECT TOP %s id FROM %s%s)" % (kwargs['offset'], opts.db_table, (order_by and " ORDER BY " + order_by or ""))) | 
|---|
| 24 | else: | 
|---|
| 25 | -        limit_sql = "" | 
|---|
| 26 | +        if kwargs.get('limit') is not None: | 
|---|
| 27 | +            limit_sql = " LIMIT %s " % kwargs['limit'] | 
|---|
| 28 | +            if kwargs.get('offset') is not None and kwargs['offset'] != 0: | 
|---|
| 29 | +                limit_sql += "OFFSET %s " % kwargs['offset'] | 
|---|
| 30 |  | 
|---|
| 31 | return select, " FROM " + ",".join(tables) + (where and " WHERE " + " AND ".join(where) or "") + (order_by and " ORDER BY " + order_by or "") + limit_sql, params | 
|---|
| 32 |  | 
|---|
| 33 | @@ -1302,7 +1312,15 @@ | 
|---|
| 34 | if field.null: | 
|---|
| 35 | kwargs.setdefault('where', []).append('%s.%s IS NOT NULL' % (opts.db_table, field.name)) | 
|---|
| 36 | select, sql, params = function_get_sql_clause(opts, **kwargs) | 
|---|
| 37 | -    sql = 'SELECT %s %s GROUP BY 1 ORDER BY 1' % (db.get_date_trunc_sql(kind, '%s.%s' % (opts.db_table, field.name)), sql) | 
|---|
| 38 | + | 
|---|
| 39 | +    #gheorghe | 
|---|
| 40 | +    from django.conf.settings import DATABASE_ENGINE | 
|---|
| 41 | +    if DATABASE_ENGINE=="ado_mssql": | 
|---|
| 42 | +        datepart = db.get_date_trunc_sql(kind, '%s.%s' % (opts.db_table, field.name)) | 
|---|
| 43 | +        sql = 'SELECT %s %s GROUP BY %s ORDER BY %s' % (datepart, sql, datepart, datepart) | 
|---|
| 44 | +    else: | 
|---|
| 45 | +        sql = 'SELECT %s %s GROUP BY 1 ORDER BY 1' % (db.get_date_trunc_sql(kind, '%s.%s' % (opts.db_table, field.name)), sql) | 
|---|
| 46 | + | 
|---|
| 47 | cursor = db.db.cursor() | 
|---|
| 48 | cursor.execute(sql, params) | 
|---|
| 49 | # We have to manually run typecast_timestamp(str()) on the results, because | 
|---|