当前位置:网站首页>[QT] Chapter 10: Database

[QT] Chapter 10: Database

2022-06-23 18:29:00 Yadong classmate

Chapter ten : database

  1. The main :
    Create connection : Will create a QSqIDatabase class Example , Only a call open() Function before the connection can be used .
    QSqlQuery class An interface is provided , Used to perform SQL Statement and browse the result set of the query . To execute a SQL sentence , You simply create one QSqlQuery object , And then call QSqlQuery : : ex-ec() Function , for example :
QSqlQuery query;
query.exec( "select * from student");
  1. QTSQL modular :QTSQL modular
    Can pass QSqIDatabase::drivers() Method to get the current sql Which databases are supported in the module .
  2. When creating multiple connections , Connection name should be specified , Can't default
QSqlDatabase  db1 = QSqIDatabase::addDatabase("QSQLITE",connect1);
QSqlDatabase db2 = QSqlDatabase::addDatabase("QSQLITE",connect2);

Query result set :
seek(int n) : query Point to the second part of the result set n Bar record . Specify the current location
first() : query The first record pointing to the result set .
last() : query Points to the last record in the result set .
next() : query Point to the next record , Every time the function is executed , It points to the next adjacent record .previous(): Point to previous record , Every time the function is executed , It points to the next record .record(): Get the record you are pointing to .
value(int n): Get the value of the property . among n Represents the second page of your query n Attributes
query.at():l obtain query The number of the record in the result set query.record().indexOf(“name”):ll return "name" The column number of
query.record().count():l Get the attributes in each record ( Namely column ) The number of
Record.field(n):ll Get the current record's n A field

  1. The core :
    increase Delete check Change
原网站

版权声明
本文为[Yadong classmate]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206231732344808.html