void MainWindow::createTable(QString tableName){ QSqlQuery query; QString str = "create table "; str.append(tableName); str.append(" (id int primary key, firstname varchar(20), lastname varchar(20));"); if(!query.exec(str)) { qDebug()<<"Unable to create a table"; } //query.exec("insert into gruppa_4 values(777, 'Peeg', 'Young')"); //query.exec("insert into gruppa_4 values(888, 'Christine', 'Holand')"); //query.exec("insert into gruppa_4 values(999, 'Lars', 'Gordon')"); //query.exec("insert into gruppa_4 values(111, 'Roberto', 'Robitaille')"); //qDebug()<<tableName;}
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName("MyDB.sqlite"); if (db.open()) { QString Query = "CREATE TABLE TEST (id INT);"; if (!db.exec(Query).isValid()) { qDebug(":("); } } db.close();
db.setDatabaseName(":memory:");
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");//db.setDatabaseName(":memory:");db.setDatabaseName("ddd.sqlite");if (!db.open()) { return false; } QSqlQuery query;query.exec("create table gruppa_1 (id int primary key, " "firstname varchar(20), lastname varchar(20))"); query.exec("insert into gruppa_1 values(1, 'Peeg', 'Young')"); query.exec("insert into gruppa_1 values(2, 'Christine', 'Holand')"); query.exec("insert into gruppa_1 values(3, 'Lars', 'Gordon')"); db.close();
db.setDatabaseName("C:/Some_Folder/ddd.sqlite");