[grassyknoll commit] r964 - branches/unhork/grassyknoll/backend/sql

0 views
Skip to first unread message

codesite...@google.com

unread,
Dec 29, 2008, 11:41:58 AM12/29/08
to grassykno...@googlegroups.com
Author: jemfinch
Date: Mon Dec 29 08:41:35 2008
New Revision: 964

Modified:
branches/unhork/grassyknoll/backend/sql/SqliteCollection.py

Log:
Issue #161: Changed SqliteCollection to support the same "connect"
classmethod interface that MysqlCollection supports.

Modified: branches/unhork/grassyknoll/backend/sql/SqliteCollection.py
==============================================================================
--- branches/unhork/grassyknoll/backend/sql/SqliteCollection.py (original)
+++ branches/unhork/grassyknoll/backend/sql/SqliteCollection.py Mon Dec 29
08:41:35 2008
@@ -84,17 +84,6 @@

__register_adapters_and_converters()

-def make_connection(filename, cached_statements):
- ## disable check_same_thread s.t. connections can be used in a
- ## different thread than they're created. As of sqlite 3.3.1, this is
- ## safe. See:
- ## http://www.sqlite.org/faq.html#q6
- ##
http://initd.org/pub/software/pysqlite/doc/usage-guide.html#extensions-and-caveats
-
- return sqlite3.connect(filename,
- detect_types=sqlite3.PARSE_DECLTYPES,
- cached_statements=cached_statements,
- check_same_thread=False)

class SqliteCollection(SqlCollection, FileBasedCollection):
def __init__(self, location, cache_size=None,
@@ -111,7 +100,7 @@
@type synchronous_writes: str, either 'FULL', 'NORMAL', or 'OFF'
"""
super(SqliteCollection, self).__init__(location)
- self.connection = make_connection(self.location.path,
cached_statements)
+ self.connection = self.connect(self.location, cached_statements)
if synchronous_writes is not None:
self.pragma(self.connection, 'synchronous', synchronous_writes)
if cache_size is not None:
@@ -119,6 +108,18 @@
self.connection.commit()

@classmethod
+ def connect(cls, location, cached_statements=None):
+ ## disable check_same_thread s.t. connections can be used in a
+ ## different thread than they're created. As of sqlite 3.3.1, this
is
+ ## safe. See:
+ ## http://www.sqlite.org/faq.html#q6
+ ##
http://initd.org/pub/software/pysqlite/doc/usage-guide.html#extensions-and-caveats
+ return sqlite3.connect(location.path,
+ detect_types=sqlite3.PARSE_DECLTYPES,
+ cached_statements=cached_statements,
+ check_same_thread=False)
+
+ @classmethod
def pragma(cls, connection, name, value):
connection.execute('PRAGMA %s = %s' % (name, value))

@@ -128,13 +129,9 @@
True # XXX: check whether the table exists

@classmethod
- def tableExists(cls, name):
- return True # XXX
-
- @classmethod
def _allocate(cls, location, page_size=None):
assert isinstance(location.table, TableMaker.Table)
- connection = make_connection(location.path, 0)
+ connection = cls.connect(location, 0)
if page_size is not None:
cls.pragma(connection, 'page_size', page_size)
location.table.create(connection.cursor())

Reply all
Reply to author
Forward
0 new messages