Ejemplo n.º 1
0
    def getObject(self, row):
        val = self.data(self.index(row, 0), Qt.UserRole)
        fld = val if val is not None else self._getNewObject()
        fld.name = self.data(self.index(row, 0)) or ""

        typestr = self.data(self.index(row, 1)) or ""
        regex = QRegExp("([^\(]+)\(([^\)]+)\)")
        startpos = regex.indexIn(typestr)
        if startpos >= 0:
            fld.dataType = regex.cap(1).strip()
            fld.modifier = regex.cap(2).strip()
        else:
            fld.modifier = None
            fld.dataType = typestr

        fld.notNull = self.data(self.index(row, 2),
                                Qt.CheckStateRole) == Qt.Unchecked
        fld.primaryKey = self.data(self.index(row, 1), Qt.UserRole)
        return fld
Ejemplo n.º 2
0
    def getSpatialRefInfo(self, srid):
        if not self.has_spatial:
            return

        try:
            c = self._execute(
                None,
                "SELECT srtext FROM spatial_ref_sys WHERE srid = '%d'" % srid)
        except DbError:
            return
        sr = self._fetchone(c)
        self._close_cursor(c)
        if sr is None:
            return

        srtext = sr[0]
        # try to extract just SR name (should be quoted in double quotes)
        regex = QRegExp('"([^"]+)"')
        if regex.indexIn(srtext) > -1:
            srtext = regex.cap(1)
        return srtext