コード例 #1
0
 def getrow(self, cl, objectid, extra_sql=[]):
     qcl = pg._join_parts(self._split_schema(cl)) # build qualified name
     extra_sql.append ( '*' )
     
     q = 'SELECT {0} FROM {1} WHERE "objectid" = \'{2}\' LIMIT 1'.format( ",".join(extra_sql), qcl, objectid)
     res = self.query (q).dictresult()
     if res:
         return res[0]
     else:
         raise pg.DatabaseError ( 'No such record (objectid={0})'.format(objectid) )
コード例 #2
0
        def delete(self, cl, a):
            """Delete an existing row in a database table.

	    This method deletes the row from a table.
	    It deletes based on the objectid	    
	    """
            qcl = pg._join_parts(self._split_schema(cl)) # build qualified name	    
            
            q = 'DELETE FROM %s WHERE objectid=%s' % (qcl, a['objectid'] )
            self._do_debug(q)
            self.db.query(q)
コード例 #3
0
 def delete(self, cl, a):
     """Delete an existing row in a database table.
 
     This method deletes the row from a table.
     It deletes based on the objectid	    
     """
     qcl = pg._join_parts(self._split_schema(cl)) # build qualified name	    
     
     q = 'DELETE FROM %s WHERE objectid=%s' % (qcl, a['objectid'] )
     self._do_debug(q)
     self.db.query(q)
コード例 #4
0
        def getrow(self, cl, objectid, extra_sql=[]):
            qcl = pg._join_parts(
                self._split_schema(cl))  # build qualified name
            extra_sql.append('*')

            q = 'SELECT {0} FROM {1} WHERE "objectid" = \'{2}\' LIMIT 1'.format(
                ",".join(extra_sql), qcl, objectid)
            res = self.query(q).dictresult()
            if res:
                return res[0]
            else:
                raise pg.DatabaseError(
                    'No such record (objectid={0})'.format(objectid))
コード例 #5
0
 def _get_attnames(self, cl):
     cl = self.__db._split_schema(cl)
     qcl = pg._join_parts(cl)
     if qcl in self.__db._attnames:
         return self.__db._attnames[qcl]
     if qcl not in self.__db.get_relations('rv'):
         raise pg.ProgrammingError('Class %s does not exist' % qcl)
     t = {}
     for att, typ in self.__db.db.query(
             "SELECT pg_attribute.attname,"
             " pg_type.typname FROM pg_class"
             " JOIN pg_namespace ON pg_class.relnamespace = pg_namespace.oid"
             " JOIN pg_attribute ON pg_attribute.attrelid = pg_class.oid"
             " JOIN pg_type ON pg_type.oid = pg_attribute.atttypid"
             " WHERE pg_namespace.nspname = '%s' AND pg_class.relname = '%s'"
             " AND (pg_attribute.attnum > 0 or pg_attribute.attname = 'oid')"
             " AND pg_attribute.attisdropped = 'f'" % cl).getresult():
         if typ.startswith('bool'):
             t[att] = 'bool'
         elif typ.startswith('abstime') or typ.startswith(
                 'date') or typ.startswith('interval'):
             t[att] = 'date'
         elif typ.startswith('timestamp'):
             t[att] = 'datetime'
         elif typ.startswith('money'):
             t[att] = 'money'
         elif typ.startswith('numeric'):
             t[att] = 'num'
         elif typ.startswith('float'):
             t[att] = 'float'
         elif typ.startswith('int') or typ.startswith('oid'):
             t[att] = 'int'
         elif typ.startswith('uuid'):
             t[att] = 'uuid'
         else:
             t[att] = 'text'
     self.__db._attnames[qcl] = t  # cache it
     return self.__db._attnames[qcl]
コード例 #6
0
 def _get_attnames(self, cl):
     cl = self.__db._split_schema(cl)
     qcl = pg._join_parts(cl)
     if qcl in self.__db._attnames:
         return self.__db._attnames[qcl]
     if qcl not in self.__db.get_relations('rv'):
         raise pg.ProgrammingError('Class %s does not exist' % qcl)
     t = {}
     for att, typ in self.__db.db.query("SELECT pg_attribute.attname,"
         " pg_type.typname FROM pg_class"
         " JOIN pg_namespace ON pg_class.relnamespace = pg_namespace.oid"
         " JOIN pg_attribute ON pg_attribute.attrelid = pg_class.oid"
         " JOIN pg_type ON pg_type.oid = pg_attribute.atttypid"
         " WHERE pg_namespace.nspname = '%s' AND pg_class.relname = '%s'"
         " AND (pg_attribute.attnum > 0 or pg_attribute.attname = 'oid')"
         " AND pg_attribute.attisdropped = 'f'"
             % cl).getresult():
         if typ.startswith('bool'):
             t[att] = 'bool'
         elif typ.startswith('abstime') or typ.startswith('date') or typ.startswith('interval'):
             t[att] = 'date'
         elif typ.startswith('timestamp'):
             t[att] = 'datetime'
         elif typ.startswith('money'):
             t[att] = 'money'
         elif typ.startswith('numeric'):
             t[att] = 'num'
         elif typ.startswith('float'):
             t[att] = 'float'
         elif typ.startswith('int') or typ.startswith('oid'):
             t[att] = 'int'
         elif typ.startswith('uuid'):
             t[att] = 'uuid'
         else:
             t[att] = 'text'
     self.__db._attnames[qcl] = t # cache it
     return self.__db._attnames[qcl]