summaryrefslogtreecommitdiff
path: root/django/db/backends/sqlite3
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2007-07-01 01:17:51 +0000
committerAdrian Holovaty <adrian@holovaty.com>2007-07-01 01:17:51 +0000
commit6f4e933fcc78da11ec43214efd3472192030eced (patch)
treed92140118d3afa00bcd909f475dd1a694c15c08f /django/db/backends/sqlite3
parent7a981380def046f753ff70a7c25efcd781ff6ac6 (diff)
newforms-admin: Merged to [5571]
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@5572 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/backends/sqlite3')
-rw-r--r--django/db/backends/sqlite3/base.py35
1 files changed, 32 insertions, 3 deletions
diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py
index 5cd67a32f5..c4ecf5f578 100644
--- a/django/db/backends/sqlite3/base.py
+++ b/django/db/backends/sqlite3/base.py
@@ -64,9 +64,10 @@ class DatabaseWrapper(local):
}
kwargs.update(self.options)
self.connection = Database.connect(**kwargs)
- # Register extract and date_trunc functions.
+ # Register extract, date_trunc, and regexp functions.
self.connection.create_function("django_extract", 2, _sqlite_extract)
self.connection.create_function("django_date_trunc", 2, _sqlite_date_trunc)
+ self.connection.create_function("regexp", 2, _sqlite_regexp)
cursor = self.connection.cursor(factory=SQLiteCursorWrapper)
cursor.row_factory = utf8rowFactory
if settings.DEBUG:
@@ -107,7 +108,14 @@ class SQLiteCursorWrapper(Database.Cursor):
def convert_query(self, query, num_params):
return query % tuple("?" * num_params)
+allows_group_by_ordinal = True
+allows_unique_and_pk = True
+autoindexes_primary_keys = True
+needs_datetime_string_cast = True
+needs_upper_for_iops = False
supports_constraints = False
+supports_tablespaces = False
+uses_case_insensitive_names = False
def quote_name(name):
if name.startswith('"') and name.endswith('"'):
@@ -139,6 +147,9 @@ def get_date_trunc_sql(lookup_type, field_name):
# sqlite doesn't support DATE_TRUNC, so we fake it as above.
return 'django_date_trunc("%s", %s)' % (lookup_type.lower(), field_name)
+def get_datetime_cast_sql():
+ return None
+
def get_limit_offset_sql(limit, offset=None):
sql = "LIMIT %s" % limit
if offset and offset != 0:
@@ -160,11 +171,20 @@ def get_drop_foreignkey_sql():
def get_pk_default_value():
return "NULL"
+def get_max_name_length():
+ return None
+
+def get_start_transaction_sql():
+ return "BEGIN;"
+
+def get_autoinc_sql(table):
+ return None
+
def get_sql_flush(style, tables, sequences):
"""Return a list of SQL statements required to remove all data from
all tables in the database (without actually removing the tables
themselves) and put the database in an empty 'initial' state
-
+
"""
# NB: The generated SQL below is specific to SQLite
# Note: The DELETE FROM... SQL generated below works for SQLite databases
@@ -182,7 +202,7 @@ def get_sql_sequence_reset(style, model_list):
"Returns a list of the SQL statements to reset sequences for the given models."
# No sequence reset required
return []
-
+
def _sqlite_date_trunc(lookup_type, dt):
try:
dt = util.typecast_timestamp(dt)
@@ -195,6 +215,13 @@ def _sqlite_date_trunc(lookup_type, dt):
elif lookup_type == 'day':
return "%i-%02i-%02i 00:00:00" % (dt.year, dt.month, dt.day)
+def _sqlite_regexp(re_pattern, re_string):
+ import re
+ try:
+ return bool(re.search(re_pattern, re_string))
+ except:
+ return False
+
# SQLite requires LIKE statements to include an ESCAPE clause if the value
# being escaped has a percent or underscore in it.
# See http://www.sqlite.org/lang_expr.html for an explanation.
@@ -203,6 +230,8 @@ OPERATOR_MAPPING = {
'iexact': "LIKE %s ESCAPE '\\'",
'contains': "LIKE %s ESCAPE '\\'",
'icontains': "LIKE %s ESCAPE '\\'",
+ 'regex': 'REGEXP %s',
+ 'iregex': "REGEXP '(?i)' || %s",
'gt': '> %s',
'gte': '>= %s',
'lt': '< %s',