Exemple #1
0
  def __init__(self, dbname = 'dumptruck.db', vars_table = '_dumptruckvars', vars_table_tmp = '_dumptruckvarstmp', auto_commit = True, adapt_and_convert = True):

    self.sqlite3 = __import__('sqlite3')

    if adapt_and_convert:
        register_adapters_and_converters(self.sqlite3)
    else:
        replace_date_converter(self.sqlite3)

    # Should database changes be committed automatically after each command?
    if type(auto_commit) != bool:
      raise TypeError('auto_commit must be True or False.')
    else:
      self.auto_commit = auto_commit

    # Database connection
    if type(dbname) not in [unicode, str]:
      raise TypeError('dbname must be a string')
    else:
      self.connection=self.sqlite3.connect(dbname, detect_types = self.sqlite3.PARSE_DECLTYPES)
      self.cursor=self.connection.cursor()

    # Make sure it's a good table name
    if type(vars_table) not in [unicode, str]:
      raise TypeError('vars_table must be a string')
    else:
      self.__vars_table = vars_table

    # Make sure it's a good table name
    if type(vars_table_tmp) not in [unicode, str]:
      raise TypeError('vars_table_tmp must be a string')
    else:
      self.__vars_table_tmp = vars_table_tmp
Exemple #2
0
# DumpTruck is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Public License for more details.

# You should have received a copy of the GNU Public License
# along with DumpTruck.  If not, see <http://www.gnu.org/licenses/>.

import sqlite3
import re
import datetime
from collections import OrderedDict
from convert import convert, quote, simplify
from adapters_and_converters import register_adapters_and_converters, Pickle

register_adapters_and_converters(sqlite3)
del(register_adapters_and_converters)

PYTHON_SQLITE_TYPE_MAP={
  unicode: u'text',
  str: u'text',

  int: u'integer',
  long: u'integer',
  bool: u'boolean',
  float: u'real',

  datetime.date: u'date',
  datetime.datetime: u'datetime',

  dict: u'json text',