Changeset 842

Show
Ignore:
Timestamp:
03/13/07 11:55:07 (2 years ago)
Author:
mfenniak
Message:

Complete DB-API implementation.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • pg8000/trunk/pg8000.py

    r841 r842  
    3636import decimal 
    3737import threading 
     38import time 
    3839 
    3940class Warning(StandardError): 
     
    367368    connect = staticmethod(connect) 
    368369 
     370    def Date(year, month, day): 
     371        return datetime.date(year, month, day) 
     372    Date = staticmethod(Date) 
     373 
     374    def Time(hour, minute, second): 
     375        return datetime.time(hour, minute, second) 
     376    Time = staticmethod(Time) 
     377 
     378    def Timestamp(year, month, day, hour, minute, second): 
     379        return datetime.datetime(year, month, day, hour, minute, second) 
     380    Timestamp = staticmethod(Timestamp) 
     381 
     382    def DateFromTicks(ticks): 
     383        return DBAPI.Date(*time.localtime(ticks)[:3]) 
     384    DateFromTicks = staticmethod(DateFromTicks) 
     385 
     386    def TimeFromTicks(ticks): 
     387        return DBAPI.Time(*time.localtime(ticks)[3:6]) 
     388    TimeFromTicks = staticmethod(TimeFromTicks) 
     389 
     390    def TimestampFromTicks(ticks): 
     391        return DBAPI.Timestamp(*time.localtime(ticks)[:6]) 
     392    TimestampFromTicks = staticmethod(TimestampFromTicks) 
     393 
     394    def Binary(value): 
     395        return Bytea(value) 
     396    Binary = staticmethod(Binary) 
     397 
     398    # I have no idea what this would be used for by a client app.  Should it be 
     399    # TEXT, VARCHAR, CHAR?  It will only compare against row_description's 
     400    # type_code if it is this one type.  It is the TEXT type_oid for now. 
     401    STRING = 25 
     402 
     403    # bytea type_oid 
     404    BINARY = 17 
     405 
     406    # numeric type_oid 
     407    NUMBER = 1700 
     408 
     409    # timestamp type_oid 
     410    DATETIME = 1114 
     411 
     412    # oid type_oid 
     413    ROWID = 26 
     414 
    369415 
    370416## 
  • pg8000/trunk/pg8000-test.py

    r841 r842  
    215215            dbapi.paramstyle = orig_paramstyle 
    216216 
     217    def TestArraysize(self): 
     218        c1 = db2.cursor() 
     219        c1.arraysize = 3 
     220        c1.execute("SELECT * FROM t1") 
     221        retval = c1.fetchmany() 
     222        self.assert_(len(retval) == c1.arraysize, 
     223                "fetchmany returned wrong number of rows") 
     224 
     225    def TestDate(self): 
     226        val = dbapi.Date(2001, 2, 3) 
     227        self.assert_(val == datetime.date(2001, 2, 3), 
     228                "Date constructor value match failed") 
     229 
     230    def TestTime(self): 
     231        val = dbapi.Time(4, 5, 6) 
     232        self.assert_(val == datetime.time(4, 5, 6), 
     233                "Time constructor value match failed") 
     234 
     235    def TestTimestamp(self): 
     236        val = dbapi.Timestamp(2001, 2, 3, 4, 5, 6) 
     237        self.assert_(val == datetime.datetime(2001, 2, 3, 4, 5, 6), 
     238                "Timestamp constructor value match failed") 
     239 
     240    def TestDateFromTicks(self): 
     241        val = dbapi.DateFromTicks(1173804319) 
     242        self.assert_(val == datetime.date(2007, 3, 13), 
     243                "DateFromTicks constructor value match failed") 
     244 
     245    def TestTimeFromTicks(self): 
     246        val = dbapi.TimeFromTicks(1173804319) 
     247        self.assert_(val == datetime.time(10, 45, 19), 
     248                "TimeFromTicks constructor value match failed") 
     249 
     250    def TestTimestampFromTicks(self): 
     251        val = dbapi.TimestampFromTicks(1173804319) 
     252        self.assert_(val == datetime.datetime(2007, 3, 13, 10, 45, 19), 
     253                "TimestampFromTicks constructor value match failed") 
     254 
     255    def TestBinary(self): 
     256        v = dbapi.Binary("\x00\x01\x02\x03\x02\x01\x00") 
     257        self.assert_(v == "\x00\x01\x02\x03\x02\x01\x00", 
     258                "Binary value match failed") 
     259        self.assert_(isinstance(v, pg8000.Bytea), 
     260                "Binary type match failed") 
     261 
     262 
    217263# Tests relating to type conversion. 
    218264class TypeTests(unittest.TestCase):