select COLUMN_NAME from information_schema.COLUMNS where table_name = 'your_table_name'
上述的做法有一点问题,如果多个数据库中存在你想要查询的表名,那么查询的结果会包括全部的字段信息。通过DESC information_schema.COLUMNS可以看到该表中列名为TABLE_SCHEMA是记录数据库名,因此下面的写法更为严格
select COLUMN_NAME from information_schema.COLUMNS where table_name = 'your_table_name' and table_schema = 'your_db_name'
//自己设置连接名,不使用默认连接名if (SdbSqlite.contains("Conn2sqlite"))
{
SdbSqlite = QSqlDatabase::database("Conn2sqlite")
}
else
{
SdbSqlite = QSqlDatabase::addDatabase(
"QSQLITE","Conn2sqlite")
}
SdbSqlite.setDatabaseName("FiveChess.database") //数据库名称
这是连接
if (SdbSqlite.open()){
int RltRowNumber = 0 //查询出来的结果列数
QString StrSql1 =
QString("select name,grade,integration,round,victory,defeat,rank"
" from member where account = '%0' and password = '%1'")
.arg(StrAcn,StrPsdOrNew)
QSqlQuery query1(SdbSqlite)
query1.exec(StrSql1)
while (query1.next())
{
if (SdbSqlite.driver()->hasFeature(QSqlDriver::QuerySize))
{
//速度快
RltRowNumber = query1.size()
}
else
{
//速度很慢
//实际执行的是这个
query1.last()
RltRowNumber = query1.at() + 1
}
}
SdbSqlite.close()
}
这是查询
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)