C++ (Qt)...QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");db.setDatabaseName("mydatabase");if (!db.open()) return;QSqlQuery query;query.prepare("SELECT id, checknumber FROM p_tovar WHERE p_tovar.schkod = ?");query.addBindValue(myValue);if (!query.exec()) return;...
CREATE TABLE "p_tovar" ( "id" INTEGER PRIMARY KEY NOT NULL, "schkod" TEXT, "artikul" TEXT, "name" TEXT, "ves" REAL, "edizm" TEXT, "valedizm" REAL, "cena" REAL, "dtsale" TEXT, "sumsale" REAL, "checknumber" TEXT, "taxcode" INTEGER);
C++ (Qt) QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName("mydatabase"); if (!db.open()) return -1; QString textQuery = "CREATE TABLE p_tovar (" "id INTEGER PRIMARY KEY NOT NULL," "schkod TEXT," "artikul TEXT," "name TEXT," "ves REAL," "edizm TEXT," "valedizm REAL," "cena REAL," "dtsale TEXT," "sumsale REAL," "checknumber TEXT," "taxcode INTEGER)"; QSqlQuery query(textQuery); qDebug() << query.exec(); qDebug() << query.exec("INSERT INTO p_tovar VALUES (1, 'schkod1', 'artikul1', 'name1', 1.1, 'edizm1', 1.2, 1.3, 'dtsale1', 1.4, 'checknumber1', 1.5)"); qDebug() << query.exec("INSERT INTO p_tovar VALUES (2, 'schkod2', 'artikul2', 'name2', 2.1, 'edizm2', 2.2, 2.3, 'dtsale2', 2.4, 'checknumber2', 2.5)"); qDebug() << query.exec("INSERT INTO p_tovar VALUES (3, 'schkod3', 'artikul3', 'name3', 3.1, 'edizm3', 3.2, 3.3, 'dtsale3', 3.4, 'checknumber3', 3.5)"); query.prepare("SELECT id, checknumber FROM p_tovar WHERE p_tovar.schkod = ?"); query.addBindValue("schkod2"); if (!query.exec()) return -1; while (query.next()) { qDebug() << query.value(0).toString(); qDebug() << query.value(1).toString(); }
C++ (Qt)1 query.prepare("SELECT id, checknumber FROM p_tovar WHERE p_tovar.schkod = ?");2 query.addBindValue("schkod2");3 if (!query.exec())4 return -1;
C++ (Qt) qDebug() << query.exec("INSERT INTO p_tovar VALUES (1, 'schkod1', 'artikul1', 'name1', 1.1, 'edizm1', 1.2, 1.3, 'dtsale1', 1.4, 'checknumber1', 1.5)"); qDebug() << query.exec("INSERT INTO p_tovar VALUES (2, 'schkod2', 'artikul2', 'name2', 2.1, 'edizm2', 2.2, 2.3, 'dtsale2', 2.4, 'checknumber2', 2.5)"); qDebug() << query.exec("INSERT INTO p_tovar VALUES (3, 'schkod3', 'artikul3', 'name3', 3.1, 'edizm3', 3.2, 3.3, 'dtsale3', 3.4, 'checknumber3', 3.5)"); query.prepare("SELECT id, checknumber FROM p_tovar WHERE p_tovar.schkod = ?"); QString value = "schkod2"; query.addBindValue(value); if (!query.exec()) return -1; while (query.next()) { qDebug() << query.value(0).toString(); qDebug() << query.value(1).toString(); }
C++ (Qt)void MainWindowImpl::selectTovar(const QString &value){ QSqlQuery scanQuery(QSqlDatabase::database()); scanQuery.prepare("SELECT id, checknumber FROM p_tovar WHERE p_tovar.schkod = ?"); scanQuery.addBindValue(value); if (!scanQuery.exec()) { QApplication::beep(); QMessageBox::critical(this, QObject::tr("SQL Error"), scanQuery.lastError().text()); return; }...}
C++ (Qt)void MainWindowImpl::selectTovar(const QString &value){ QSqlQuery scanQuery(QSqlDatabase::database()); scanQuery.prepare("SELECT id, checknumber FROM p_tovar WHERE p_tovar.schkod = ?"); scanQuery.addBindValue("2900000113"); if (!scanQuery.exec()) { QApplication::beep(); QMessageBox::critical(this, QObject::tr("SQL Error"), scanQuery.lastError().text()); return; }...}