本文整理匯總了Python中qgis.PyQt.QtSql.QSqlQuery.lastError方法的典型用法代碼示例。如果您正苦於以下問題:Python QSqlQuery.lastError方法的具體用法?Python QSqlQuery.lastError怎麽用?Python QSqlQuery.lastError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類qgis.PyQt.QtSql.QSqlQuery
的用法示例。
在下文中一共展示了QSqlQuery.lastError方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __createLoggingTable
# 需要導入模塊: from qgis.PyQt.QtSql import QSqlQuery [as 別名]
# 或者: from qgis.PyQt.QtSql.QSqlQuery import lastError [as 別名]
def __createLoggingTable(self):
file_path = os.path.dirname(os.path.realpath(__file__)) + "/create_loggingtable/create_logging_table.sql"
sql = open(file_path).read()
self.__openDB()
query = QSqlQuery(self.db)
query.exec_(sql)
if(query.lastError().number() == -1):
return True
else:
return False
示例2: __insertLogEntry
# 需要導入模塊: from qgis.PyQt.QtSql import QSqlQuery [as 別名]
# 或者: from qgis.PyQt.QtSql.QSqlQuery import lastError [as 別名]
def __insertLogEntry(self,requestType,search,result):
self.__openDB()
sql = "INSERT INTO postnas_search_logging (datum,username,requestType,search,result) VALUES (:datum,:username,:requestType,:search,:result)"
query = QSqlQuery(self.db)
query.prepare(sql)
query.bindValue(":datum",datetime.datetime.now().isoformat())
query.bindValue(":username",self.username)
query.bindValue(":requestType",requestType)
query.bindValue(":search",search)
query.bindValue(":result",str(result).replace("u'","'").replace("\'","\"").replace("[","{").replace("]","}"))
query.exec_()
if(query.lastError().number() == -1):
return True
else:
return False
示例3: fetchall
# 需要導入模塊: from qgis.PyQt.QtSql import QSqlQuery [as 別名]
# 或者: from qgis.PyQt.QtSql.QSqlQuery import lastError [as 別名]
def fetchall(self, db, sql):
rows = []
qry = QSqlQuery(db)
if qry.exec_(sql):
rec = qry.record()
while qry.next():
row = {}
for i in range(0, rec.count()):
v = "%s" % qry.value(i)
if v == "NULL":
v = ''
row[rec.fieldName(i)] = v.strip()
rows.append(row)
else:
qDebug("Exec failed: " + qry.lastError().text())
return rows
示例4: QtSqlDBCursor
# 需要導入模塊: from qgis.PyQt.QtSql import QSqlQuery [as 別名]
# 或者: from qgis.PyQt.QtSql.QSqlQuery import lastError [as 別名]
class QtSqlDBCursor(object):
def __init__(self, conn):
self.qry = QSqlQuery(conn)
self.description = None
self.rowcount = -1
self.arraysize = 1
def close(self):
self.qry.finish()
def execute(self, operation, parameters=[]):
if len(parameters) == 0:
if not self.qry.exec_(operation):
raise ExecError(self.qry.lastError().databaseText())
else:
if not self.qry.prepare(operation):
raise ExecError(self.qry.lastError().databaseText())
for i in range(len(parameters)):
self.qry.bindValue(i, parameters[i])
if not self.qry.exec_():
raise ExecError(self.qry.lastError().databaseText())
self.rowcount = self.qry.size()
self.description = []
for c in range(self.qry.record().count()):
f = self.qry.record().field(c)
if f.type() == QVariant.Date:
t = Date
elif f.type() == QVariant.Time:
t = Time
elif f.type() == QVariant.DateTime:
t = Timestamp
elif f.type() == QVariant.Double:
t = float
elif f.type() == QVariant.Int:
t = int
elif f.type() == QVariant.String:
t = str
elif f.type() == QVariant.ByteArray:
t = str
else:
continue
self.description.append([
f.name(), # name
t, # type_code
f.length(), # display_size
f.length(), # internal_size
f.precision(), # precision
None, # scale
f.requiredStatus() != QSqlField.Required # null_ok
])
def executemany(self, operation, seq_of_parameters):
if len(seq_of_parameters) == 0:
return
if not self.qry.prepare(operation):
raise ExecError(self.qry.lastError().databaseText())
for r in seq_of_parameters:
for i in range(len(r)):
self.qry.bindValue(i, r[i])
if not self.qry.exec_():
raise ExecError(self.qry.lastError().databaseText())
def scroll(self, row):
return self.qry.seek(row)
def fetchone(self):
if not next(self.qry):
return None
row = []
for i in range(len(self.description)):
value = self.qry.value(i)
if (isinstance(value, QDate) or
isinstance(value, QTime) or
isinstance(value, QDateTime)):
value = value.toString()
elif isinstance(value, QByteArray):
value = u"GEOMETRY"
# value = value.toHex()
row.append(value)
return row
def fetchmany(self, size=10):
rows = []
while len(rows) < size:
row = self.fetchone()
if row is None:
break
rows.append(row)
#.........這裏部分代碼省略.........