Exemplo n.º 1
0
    def check_types(self):
        fInt = 5982374
        fString = "this\\'is'\na string"

        # text and blob are really the same, at least on MySQL,
        # but we'll test them both anyway..
        import string
        fText = string.join(map(chr, range(256)),'') # test all ASCII characters
        fBlob = fText + open('test/testRecord.pyc',"r").read() # our own bytecodes :)

        rec = zdc.Record(zdc.Table(zdc.test.dbc, "test_types"))
        rec["f_int"] = fInt
        rec["f_string"] = fString
        rec["f_text"] = fText
        rec["f_blob"] = fBlob
        rec.save()

        # test that it WRITES them correctly:
        self.cur.execute(
            "SELECT f_int, f_string, f_text, f_blob from test_types where ID=1")

        row = self.cur.fetchone()
        assert row is not None, \
               "Record didn't write data at all!"
        assert row[0] == fInt, \
               "Record doesn't save ints correctly"
        assert row[1] == fString, \
               "Record doesn't save strings correctly"

        for i in range(len(fText)):
            assert row[2][i] == fText[i], \
                   "Record: saves chr(%s) wrong in text fields. (got: %s wanted: %s)" \
                   % (i, repr(row[2][i]), repr(fText[i]))

        assert row[2] == fText, \
               "Record doesn't save texts correctly"


        assert row[3] == fBlob, \
               "Record doesn't save blobs correctly"
        
        
        # also test that it READS them correctly:
        rec = zdc.Table(zdc.test.dbc, "test_types").fetch(1)
        assert rec["f_int"] == fInt, \
               "Record doesn't retrieve ints correctly."
        assert rec["f_string"] == fString, \
               "Record doesn't retrieve strings correctly."
        assert rec["f_text"] == fText, \
               "Record doesn't retrieve texts correctly."
        assert rec["f_blob"] == fBlob, \
               "Record doesn't retrieve blobs correctly."
Exemplo n.º 2
0
    def _fetch(self, key=None, **kw):
        keys = kw.keys()
        if len(keys) > 1:
            # multi-colum might actually work, but I wouldn't bet on it, so
            # I'm preventing it for now...
            raise Error, \
                  "User._fetch can't cope with multiple columns yet."

        elif (len(keys)==1) and (keys[0] in ['username', 'password']):
            # search by the detail record..
            table = zdc.Table(self._ds, "base_user")
            self._userRec = apply(table.fetch, (), kw)
            apply(self.__super._fetch, (self,), {"ID":self._userRec["ID"]})

        else:
            # search by the master record..
            apply(self.__super._fetch, (self,), kw)
            self._userRec = zdc.Table(self._ds, "base_user").fetch(self.ID)
Exemplo n.º 3
0
    def check_quotes(self):
        #@TODO: clean up this sickening lack of encapsulation :)
        table = zdc.Table(zdc.test.dbc, "test_fish")
        assert table.dbc.source._sqlQuote(table.name, "fish", "foo'fish") \
               == "'foo\\'fish'", \
               "quoting failed for STRING"
        assert table.dbc.source._sqlQuote(table.name, "ID", 0) == "0",\
               "quotes failed for NUMBER"

        assert table.dbc.source._sqlQuote(table.name, "ID", 1L) == "1",\
               "quotes failed for long NUMBER"
Exemplo n.º 4
0
    def __init__(self, ds, **where):

        # make isclerk non-optional and you'll get
        # an error if it's not clerk (only for smoketest
        # while I'm refactoring this class out of existence)

        # ds turned out to be a bad idea.
        if ds:
            # you can do:
            # >>> obj = RecordObject(ds, tablename)
            #
            # OR you can define a class:
            #
            # >>> class Person(zdc.RecordObject):
            # >>>   _tablename = "mas_person"
            # >>>
            # >>> Person(ds)
            import warnings
            #raise "record objects should no longer use ds"
            #warnings.warn("record objects should no longer use ds")
            self.__dict__['_ds'] = ds
            self.__dict__['_table'] = zdc.Table(self._ds, self._tablename)

            # old-style compatability:
            self.__dict__['_data'] = self.__values__
            self.__dict__['_record'] = None

        # if all's well, go ahead with the init:
        super(RecordObject, self).__init__(**where)

        self._link()
        self._init()
        if where:
            self._fetch(**where)
        else:
            self._new()
Exemplo n.º 5
0
 def setUp(self):
     self.cur = zdc.test.dbc.cursor()
     self.cur.execute("delete from test_fish")
     self.cur.execute("delete from test_types")
     self.table = zdc.Table(zdc.test.dbc, "test_fish")
Exemplo n.º 6
0
 def _new(self):
     self.__super._new(self)
     self._userRec = zdc.Table(self._ds, "base_user").new()