Django

Code

Changeset 1484

Show
Ignore:
Timestamp:
11/28/05 20:05:32 (3 years ago)
Author:
adrian
Message:

Fixed #460 -- Added 'django-admin.py inspectdb' support for SQLite. Thanks, Swaroop

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/AUTHORS

    r1458 r1484  
    7575    sopel 
    7676    Radek Švarz <http://www.svarz.cz/translate/> 
     77    Swaroop C H <http://www.swaroopch.info> 
    7778    Aaron Swartz <http://www.aaronsw.com/> 
    7879    Tom Tobin 
  • django/trunk/django/core/db/backends/ado_mssql.py

    r1326 r1484  
    113113    raise NotImplementedError 
    114114 
     115def get_table_description(cursor, table_name): 
     116    raise NotImplementedError 
     117 
    115118def get_relations(cursor, table_name): 
    116119    raise NotImplementedError 
  • django/trunk/django/core/db/backends/mysql.py

    r1326 r1484  
    124124    cursor.execute("SHOW TABLES") 
    125125    return [row[0] for row in cursor.fetchall()] 
     126 
     127def get_table_description(cursor, table_name): 
     128    "Returns a description of the table, with the DB-API cursor.description interface." 
     129    cursor.execute("SELECT * FROM %s LIMIT 1" % table_name) 
     130    return cursor.description 
    126131 
    127132def get_relations(cursor, table_name): 
  • django/trunk/django/core/db/backends/postgresql.py

    r1326 r1484  
    100100            AND pg_catalog.pg_table_is_visible(c.oid)""") 
    101101    return [row[0] for row in cursor.fetchall()] 
     102 
     103def get_table_description(cursor, table_name): 
     104    "Returns a description of the table, with the DB-API cursor.description interface." 
     105    cursor.execute("SELECT * FROM %s LIMIT 1" % table_name) 
     106    return cursor.description 
    102107 
    103108def get_relations(cursor, table_name): 
  • django/trunk/django/core/db/backends/sqlite3.py

    r1326 r1484  
    125125 
    126126def get_table_list(cursor): 
    127     raise NotImplementedError 
     127    cursor.execute("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name") 
     128    return [row[0] for row in cursor.fetchall()] 
     129 
     130def get_table_description(cursor, table_name): 
     131    cursor.execute("PRAGMA table_info(%s)" % table_name) 
     132    return [(row[1], row[2], None, None) for row in cursor.fetchall()] 
    128133 
    129134def get_relations(cursor, table_name): 
  • django/trunk/django/core/db/__init__.py

    r1213 r1484  
    3636get_random_function_sql = dbmod.get_random_function_sql 
    3737get_table_list = dbmod.get_table_list 
     38get_table_description = dbmod.get_table_description 
    3839get_relations = dbmod.get_relations 
    3940OPERATOR_MAPPING = dbmod.OPERATOR_MAPPING 
  • django/trunk/django/core/management.py

    r1483 r1484  
    572572        except NotImplementedError: 
    573573            relations = {} 
    574         cursor.execute("SELECT * FROM %s LIMIT 1" % table_name) 
    575         for i, row in enumerate(cursor.description): 
     574        for i, row in enumerate(db.get_table_description(cursor, table_name)): 
    576575            column_name = row[0] 
    577576            if relations.has_key(i): 
     
    587586                except KeyError: 
    588587                    field_type = 'TextField' 
    589                     yield "    # The model-creator script used TextField by default, because" 
    590                     yield "    # it couldn't recognize your field type." 
     588                    field_type_was_guessed = True 
     589                else: 
     590                    field_type_was_guessed = False 
    591591                field_desc = '%s = meta.%s(' % (column_name, field_type) 
    592592                if field_type == 'CharField': 
    593593                    field_desc += 'maxlength=%s' % (row[3]) 
    594             yield '    %s)' % field_desc 
     594                field_desc += ')' 
     595                if field_type_was_guessed: 
     596                    field_desc += ' # This is a guess!' 
     597            yield '    %s' % field_desc 
    595598        yield '    class META:' 
    596599        yield '        db_table = %r' % table_name 
  • django/trunk/docs/django-admin.txt

    r1474 r1484  
    8787      doesn't yet introspect primary keys. 
    8888 
    89 ``inspectdb`` only works with PostgreSQL and MySQL. Foreign-key detection only 
    90 works in PostgreSQL. 
     89``inspectdb`` works with PostgreSQL, MySQL and SQLite. Foreign-key detection 
     90only works in PostgreSQL. In SQLite, it cannot detect column types; it'll 
     91use ``TextField`` for each column. 
    9192 
    9293install [modelmodule modelmodule ...]