move the dbi abstraction to dbi.py; I'll deal with various errors and

incompatibilities in different versions of MySQLdb here...


git-svn-id: http://viewvc.tigris.org/svn/viewvc/trunk@135 8cb11bc2-c004-0410-86c3-e597b4017df7
remotes/tags/V0_6
jpaint 2000-06-27 03:09:52 +00:00
parent ee7abc077a
commit 91d2ebfc64
4 changed files with 63 additions and 24 deletions

View File

@ -18,11 +18,7 @@ import sys
import string
import time
## imports from the database API; we re-assign the namespace here so it
## is easier to switch databases
import MySQLdb
DBI = MySQLdb
import dbi
from commit import CreateCommit, PrintCommit
@ -63,7 +59,8 @@ class CheckinDatabase:
self.dbDescriptionIDCache = {}
def Connect(self):
self.dbConn = self.SQLConnect()
self.dbConn = dbi.connect(
self.dbHost, self.dbUser, self.dbPasswd, self.dbDatabase)
def SQLGetID(self, table, field, identifier, auto_set):
sql = 'SELECT id FROM %s x WHERE x.%s="%s"' % (
@ -244,7 +241,7 @@ class CheckinDatabase:
## module to do the conversion
temp = time.localtime(commit.GetTime())
dbCI_When = DBI.Timestamp(
dbCI_When = dbi.Timestamp(
temp[0], temp[1], temp[2], temp[3], temp[4], temp[5])
dbWhoID = self.GetAuthorID(commit.GetAuthor())
@ -404,19 +401,8 @@ class CheckinDatabase:
return None
return commit
class MySQLCheckinDatabase(CheckinDatabase):
def SQLConnect(self):
return MySQLdb.connect(
host = self.dbHost,
user = self.dbUser,
passwd = self.dbPasswd,
db = self.dbDatabase)
## entrypoints
def CreateCheckinDatabase(host, user, passwd, database):
return MySQLCheckinDatabase(host, user, passwd, database)
return CheckinDatabase(host, user, passwd, database)

56
lib/dbi.py Normal file
View File

@ -0,0 +1,56 @@
# -*- Mode: python -*-
#
# Copyright (C) 2000 The ViewCVS Group. All Rights Reserved.
#
# By using this file, you agree to the terms and conditions set forth in
# the LICENSE.html file which can be found at the top level of the ViewCVS
# distribution or at http://www.lyra.org/viewcvs/license-1.html.
#
# Contact information:
# Greg Stein, PO Box 760, Palo Alto, CA, 94302
# gstein@lyra.org, http://www.lyra.org/viewcvs/
#
# -----------------------------------------------------------------------
#
import MySQLdb
dbi_error = "dbi error"
class Cursor:
def __init__(self, mysql_cursor):
self.__cursor = mysql_cursor
def execute(self, *args):
apply(self.__cursor.execute, args)
def fetchone(self):
try:
row = self.__cursor.fetchone()
except IndexError:
row = None
return row
class Connection:
def __init__(self, host, user, passwd, db):
self.__mysql = MySQLdb.connect(
host=host, user=user, passwd=passwd, db=db)
def cursor(self):
return Cursor(self.__mysql.cursor())
def Timestamp(year, month, date, hour, minute, second):
return MySQLdb.Timestamp(year, month, date, hour, minute, second)
def TimestampFromTicks(ticks):
return MySQLdb.TimestampFromTicks(ticks)
def connect(host, user, passwd, db):
return Connection(host, user, passwd, db)

View File

@ -14,11 +14,7 @@
#
import time
## imports from the database API; we re-assign the namespace here so it
## is easier to switch databases
import MySQLdb
DBI = MySQLdb
import dbi
## QueryEntry holds data on one match-type in the SQL database

View File

@ -66,6 +66,7 @@ FILE_INFO_LIST = [
("lib/config.py", "lib/config.py", 0644, 0, 0, 1),
("lib/cvsdbapi.py", "lib/cvsdbapi.py", 0644, 1, 0, 1),
("lib/database.py", "lib/database.py", 0644, 0, 0, 1),
("lib/dbi.py", "lib/dbi.py", 0644, 0, 0, 1),
("lib/popen.py", "lib/popen.py", 0644, 0, 0, 1),
("lib/py2html.py", "lib/py2html.py", 0644, 0, 0, 1),
("lib/rlog.py", "lib/rlog.py", 0644, 1, 0, 1),