Changeset 6026
- Timestamp:
- 08/30/07 07:58:04 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/gis/django/contrib/gis/db/backend/__init__.py
r6018 r6026 14 14 from django.conf import settings 15 15 from django.db import connection 16 from django.db.models.query import LOOKUP_SEPARATOR, field_choices, find_field, FieldFound, QUERY_TERMS, get_where_clause 16 from django.db.models.query import field_choices, find_field, get_where_clause, \ 17 FieldFound, LOOKUP_SEPARATOR, QUERY_TERMS 17 18 from django.utils.datastructures import SortedDict 18 qn = connection.ops.quote_name19 19 20 20 if settings.DATABASE_ENGINE == 'postgresql_psycopg2': … … 31 31 # counterparts to support constructing SQL for geographic queries. 32 32 # 33 # Status: Synced with r5 609.33 # Status: Synced with r5982. 34 34 # 35 35 def parse_lookup(kwarg_items, opts): … … 91 91 92 92 def lookup_inner(path, lookup_type, value, opts, table, column): 93 qn = connection.ops.quote_name 93 94 joins, where, params = SortedDict(), [], [] 94 95 current_opts = opts … … 247 248 # Last query term was a normal field. 248 249 column = field.column 250 db_type = field.db_type() 249 251 250 252 # If the field is a geometry field, then the WHERE clause will need to be obtained django/branches/gis/django/contrib/gis/db/backend/postgis/creation.py
r6018 r6026 7 7 8 8 def create_lang(db_name, verbosity=1): 9 " This sets up the pl/pgsql language on the given database."9 "Sets up the pl/pgsql language on the given database." 10 10 11 11 # Getting the command-line options for the shell command … … 51 51 created_regex = re.compile(r'^createdb: database creation failed: ERROR: database ".+" already exists') 52 52 def _create_with_shell(db_name, verbosity=1, autoclobber=False): 53 """If no spatial database already exists, then using a cursor will not work. Thus, a 54 `createdb` command will be issued through the shell to bootstrap the database.""" 53 """ 54 If no spatial database already exists, then using a cursor will not work. 55 Thus, a `createdb` command will be issued through the shell to bootstrap 56 creation of the spatial database. 57 """ 55 58 56 59 # Getting the command-line options for the shell command … … 81 84 82 85 def create_spatial_db(test=False, verbosity=1, autoclobber=False, interactive=False): 83 " This Python routine creates a spatial database based on settings.py."86 "Creates a spatial database based on the settings." 84 87 85 88 # Making sure we're using PostgreSQL and psycopg2 … … 120 123 121 124 def drop_db(db_name=False, test=False): 122 "Using the cursor, drops the given database. All exceptions will be propagated up." 125 """ 126 Drops the given database (defaults to what is returned from get_spatial_db(). 127 All exceptions are propagated up to the caller. 128 """ 123 129 if not db_name: db_name = get_spatial_db(test=test) 124 130 cursor = connection.cursor() … … 139 145 140 146 def get_spatial_db(test=False): 141 """This routine returns the name of the spatial database. 142 Set the 'test' keyword for the test spatial database name.""" 147 """ 148 Returns the name of the spatial database. The 'test' keyword may be set 149 to return the test spatial database name. 150 """ 143 151 if test: 144 152 if settings.TEST_DATABASE_NAME: … … 153 161 154 162 def load_postgis_sql(db_name, verbosity=1): 155 "This routine loads up the PostGIS SQL files lwpostgis.sql and spatial_ref_sys.sql." 163 """" 164 This routine loads up the PostGIS SQL files lwpostgis.sql and 165 spatial_ref_sys.sql. 166 """ 156 167 157 168 # Getting the path to the PostGIS SQL … … 161 172 sql_path = settings.POSTGIS_SQL_PATH 162 173 except AttributeError: 163 sql_path = '/usr/local/share' 174 status, sql_path = getstatusoutput('pg_config --sharedir') 175 if status != 0: 176 sql_path = '/usr/local/share' 164 177 165 178 # The PostGIS SQL post-creation files. django/branches/gis/django/contrib/gis/db/models/query.py
r6018 r6026 18 18 "Geographical-enabled QuerySet object." 19 19 20 quote_name = connection.ops.quote_name21 22 20 #### Overloaded QuerySet Routines #### 23 21 def __init__(self, model=None): … … 48 46 49 47 def _get_sql_clause(self): 48 qn = connection.ops.quote_name 50 49 opts = self.model._meta 51 50 … … 82 81 # Add any additional SELECTs. 83 82 if self._select: 84 select.extend(['(%s) AS %s' % (quote_only_if_word(s[1]), self.quote_name(s[0])) for s in self._select.items()])83 select.extend(['(%s) AS %s' % (quote_only_if_word(s[1]), qn(s[0])) for s in self._select.items()]) 85 84 86 85 # Start composing the body of the SQL statement. 87 sql = [" FROM", self.quote_name(opts.db_table)]86 sql = [" FROM", qn(opts.db_table)] 88 87 89 88 # Compose the join dictionary into SQL describing the joins. … … 108 107 for f in handle_legacy_orderlist(ordering_to_use): 109 108 if f == '?': # Special case. 110 order_by.append( backend.get_random_function_sql())109 order_by.append(connection.ops.random_function_sql()) 111 110 else: 112 111 if f.startswith('-'): … … 118 117 if "." in col_name: 119 118 table_prefix, col_name = col_name.split('.', 1) 120 table_prefix = self.quote_name(table_prefix) + '.'119 table_prefix = qn(table_prefix) + '.' 121 120 else: 122 121 # Use the database table as a column prefix if it wasn't given, 123 122 # and if the requested column isn't a custom SELECT. 124 123 if "." not in col_name and col_name not in (self._select or ()): 125 table_prefix = self.quote_name(opts.db_table) + '.'124 table_prefix = qn(opts.db_table) + '.' 126 125 else: 127 126 table_prefix = '' 128 order_by.append('%s%s %s' % (table_prefix, self.quote_name(orderfield2column(col_name, opts)), order))127 order_by.append('%s%s %s' % (table_prefix, qn(orderfield2column(col_name, opts)), order)) 129 128 if order_by: 130 129 sql.append("ORDER BY " + ", ".join(order_by)) … … 132 131 # LIMIT and OFFSET clauses 133 132 if self._limit is not None: 134 sql.append("%s " % backend.get_limit_offset_sql(self._limit, self._offset))133 sql.append("%s " % connection.ops.limit_offset_sql(self._limit, self._offset)) 135 134 else: 136 135 assert self._offset is None, "'offset' is not allowed without 'limit'" … … 145 144 #### Methods specific to the GeoQuerySet #### 146 145 def _field_column(self, field): 147 return "%s.%s" % (self.quote_name(self.model._meta.db_table), 148 self.quote_name(field.column)) 146 qn = connection.ops.quote_name 147 return "%s.%s" % (qn(self.model._meta.db_table), 148 qn(field.column)) 149 149 150 150 def kml(self, field_name, precision=8): … … 177 177 self._custom_select[field.column] = \ 178 178 '(ST_Transform(%s, %s)) AS %s' % (self._field_column(field), srid, 179 self.quote_name(field.column))179 connection.ops.quote_name(field.column)) 180 180 return self._clone() 181 181
