int main(int argc,char **argv) { DB *dbp; u_int32_t flags; char *keyvalue,*datavalue; int ret = 0; //create a standlone database if( argc < 3 || !strcmp(argv[1],"-h") ) { //printf("USAGE:\n"); //printf("\t\t%s -[w/r] keyvalue datavalue\n",argv[0]); usage(argv[0]); } else { if(strcmp(argv[1],"-w")==0) { if(argc != 4) { printf("parameters wrong, please check first!\n"); printf("use \"%s -h\" for help\n",argv[0]); } else { char *keyvalue=argv[2]; char *datavalue=argv[3]; openDB(&dbp,OPENFORWR); write_DB(dbp,keyvalue,datavalue); dbp->close(dbp,0); } } else if(strcmp(argv[1],"-r")==0) { //char result[32]={0}; char * result =(char *)malloc(32*sizeof(char)) ; char *keyvalue=argv[2]; char *datavalue=argv[3]; openDB(&dbp,OPENFORRD); read_DB(dbp,keyvalue,result); dbp->close(dbp,0); printf("The result of the %s is %s\n",keyvalue,result); } } return 0; }
QSqlQuery DBasePostgreSQL::executeSql(QString command) { if (connectDB.isOpen()==true) { openDB(); QSqlQuery query(command, getConnection()); return query; } else { openDB(); QSqlQuery query(command, getConnection()); return query; } }
double Product::getPrice(string productId) { openDB(); int result; char * errmsg = NULL; char **dbResult; //是 char ** 类型,两个*号 int nRow, nColumn; /*string SQLCode = "select * from food as th, books as de where th.productId = \"" + productId + "\" or de.productId = \"" + productId + "\";";*/ string SQLCode = "select * from product where productId = \"" + productId + "\";"; result = sqlite3_get_table(db, SQLCode.c_str(), &dbResult, &nRow, &nColumn, &errmsg); //cout << nRow << endl; //cout << errmsg << endl; //cout << dbResult[10] << endl; closeDB(); if (nRow > 0) return atof(dbResult[10]); else return -1; }
void MainWindow::openRecent() { if (recentDBsListWidget->currentIndex().isValid()) { addRecent(recentDBsListWidget->currentItem()->text()); openDB(recentDBsListWidget->currentItem()->text()); } }
void Food::showAllThisType() { openDB(); int result; char * errmsg = NULL; char **dbResult; //是 char ** 类型,两个*号 int nRow, nColumn; string SQLCode = "select * from product where type = \"food\";"; result = sqlite3_get_table(Product::db, SQLCode.c_str(), &dbResult, &nRow, &nColumn, &errmsg); cout << "-----------------------------------------------" << endl; for (int i = 1; i <= nRow; i++) { cout << "product ID:" << dbResult[i * 7 + 0] << endl; cout << "type:" << dbResult[i * 7 + 1] << endl; cout << "name:" << dbResult[i * 7 + 2] << endl; cout << "price:" << dbResult[i * 7 + 3] << endl; cout << "sales volumn:" << dbResult[i * 7 + 4] << endl; cout << "left:" << dbResult[i * 7 + 5] << endl; cout << "description:" << dbResult[i * 7 + 6] << endl; cout << "-----------------------------------------------" << endl; } closeDB(); }
int PointSqlQueryModel::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QSqlQueryModel::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: setQuery((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QSqlDatabase(*)>(_a[2]))); break; case 1: setQuery((*reinterpret_cast< const QString(*)>(_a[1]))); break; case 2: setQuery((*reinterpret_cast< const QSqlQuery(*)>(_a[1]))); break; case 3: { QVariant _r = data((*reinterpret_cast< const QModelIndex(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); if (_a[0]) *reinterpret_cast< QVariant*>(_a[0]) = _r; } break; case 4: refresh((*reinterpret_cast< double(*)>(_a[1])),(*reinterpret_cast< double(*)>(_a[2])),(*reinterpret_cast< double(*)>(_a[3]))); break; case 5: refreshSearch((*reinterpret_cast< const QString(*)>(_a[1]))); break; case 6: { QVariant _r = datasingle((*reinterpret_cast< const QString(*)>(_a[1]))); if (_a[0]) *reinterpret_cast< QVariant*>(_a[0]) = _r; } break; case 7: { bool _r = openDB(); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 8: initDB(); break; case 9: closeDB(); break; case 10: { double _r = distance((*reinterpret_cast< double(*)>(_a[1])),(*reinterpret_cast< double(*)>(_a[2])),(*reinterpret_cast< double(*)>(_a[3])),(*reinterpret_cast< double(*)>(_a[4]))); if (_a[0]) *reinterpret_cast< double*>(_a[0]) = _r; } break; default: ; } _id -= 11; } return _id; }
DatabaseEngine::DatabaseEngine(QObject *parent) : QObject(parent) { static bool initialized = false; if(!initialized){ initialized = true; openDB(); } users_ = Users::getInstance(); users_->setParent(this); users_->setDatabase(dataBase_); printheads_ = Printheads::getInstance(); printheads_->setParent(this); printheads_->setDatabase(dataBase_); cartridges_ = Cartridges::getInstance(); cartridges_->setParent(this); cartridges_->setDatabase(dataBase_); jobManager_ = JobManager::getInstance(); jobManager_->setParent(this); jobManager_->setDatabase(dataBase_); }
void MainWindow::update_tableView_Cart() { openDB(); QSqlQuery query; //doesn't involve discounts: query.prepare("select title, wm_concat(author.name), isbn, cart.price, 'Delete' " "from cart join book on cart.isbn = book.isbn " "join book_s_author ba on ba.isbn = book.isbn " "join author on ba.author_ID = author.AUTHOR_ID " "where cart.customer_id = :cust_id " "group by title, isbn, cart.price"); query.bindValue(":cust_id", current_customer_ID); /* query.prepare("select asd1.title, asd1.auth_name, asd1.isbn, nvl(asd2.discount, asd1.price), 'Delete' " "from (select title, wm_concat(author.name) auth_name, book.isbn, price, cart.bundle_id " "from cart join book on cart.isbn = book.isbn " "join book_s_author ba on ba.isbn = book.isbn " "join author on ba.author_ID = author.AUTHOR_ID " "group by title, book.isbn, price, cart.bundle_id) asd1 " "left outer join " "(select discount, isbn, bundle_id " "from bundledbook) asd2 " "on asd1.isbn = asd2.isbn and asd1.bundle_id = asd2.bundle_id");*/ qDebug()<<"TableView updated: "<<query.exec(); qDebug()<<query.lastError(); cartModel->setQuery(query); ui->label_page_count->setText(QString("Page %1 out of %2").arg(current_book_page + 1).arg(max_book_pages + 1)); cartModel->setHeaderData( 0, Qt::Horizontal, QObject::tr("Title") ); cartModel->setHeaderData( 1, Qt::Horizontal, QObject::tr("Author") ); cartModel->setHeaderData( 2, Qt::Horizontal, QObject::tr("ISBN") ); cartModel->setHeaderData( 3, Qt::Horizontal, QObject::tr("Price") ); cartModel->setHeaderData( 4, Qt::Horizontal, QObject::tr("")); closeDB(); }
void MainWindow::update_tableView_Bundles() { openDB(); QSqlQuery query; query.prepare("select name, ttl, asd1.bundle_id, trunc(prc,2), 'Add to cart' " "from " "( " "select bundle.name, wm_concat(book.title) ttl, bundle.bundle_id " "from bundle, bundledbook, book " "where book.isbn = bundledbook.isbn and bundle.bundle_id = bundledbook.bundle_id " "group by bundle.name, bundle.bundle_id " ") asd1 " "join " "( " "select sum((1-discount)*price) prc, bundle.bundle_id " "from bundle, bundledbook, book " "where book.isbn = bundledbook.isbn and bundle.deleted != 1 and bundle.bundle_id = bundledbook.bundle_id " "group by bundle.bundle_id " ") asd2 " "on asd1.bundle_id = asd2.bundle_id"); qDebug()<<"bundles update: "<<query.exec(); qDebug()<<query.lastError(); bundlesModel->setQuery(query); qDebug()<<"rows found: "<<bundlesModel->rowCount()<<"\n"; bundlesModel->setHeaderData( 0, Qt::Horizontal, QObject::tr("Bundle")); bundlesModel->setHeaderData( 1, Qt::Horizontal, QObject::tr("Books in bundle")); bundlesModel->setHeaderData( 2, Qt::Horizontal, QObject::tr("Bundle ID")); bundlesModel->setHeaderData( 3, Qt::Horizontal, QObject::tr("Price")); bundlesModel->setHeaderData( 4, Qt::Horizontal, QObject::tr("")); ui->tableView_Bundles->hideColumn(2); closeDB(); }
void Xaman::init() { //Inicializar la DB donde se guarda un registro de las maquinas openDB(); //Inicializar la interfaz de los botones para controlar remotamente los equipos initXamanButton(); //Inicializar la seccion de las playlist initPlayList(); //Inicializar el widget para contenido a presentar contenido(); connect(ui->verticalSlider, SIGNAL(valueChanged(int)), this, SLOT(setValue(int))); //Conectar los menu desplegables de cada seccion ui->Content_Shows->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui->Content_Shows,SIGNAL(customContextMenuRequested(QPoint)),this, SLOT(menu(const QPoint&))); ui->Content_Musica->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui->Content_Musica,SIGNAL(customContextMenuRequested(QPoint)),this, SLOT(menuMusica(const QPoint&))); ui->Content_Imagenes->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui->Content_Imagenes,SIGNAL(customContextMenuRequested(QPoint)),this, SLOT(menuImagenes(const QPoint&))); ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui->treeWidget,SIGNAL(customContextMenuRequested(QPoint)),this, SLOT(menuList(const QPoint&))); }
void process_choice(int choice){ BufferManager *bu = BufferManager::getBufferManager(); float hr = -1; switch(choice){ case 1: initCache(bu); break; case 2: createDB(bu); break; case 3: openDB(bu); break; case 4: readDB(bu); break; case 5: writeDB(bu); break; case 6: expandDB(bu); break; case 7: commitDB(bu); break; case 8: closeDB(bu); break; case 9: commitCache(bu); break; case 10: releaseCache(bu); break; case 11: dropDB(bu); break; case 12: cout<<endl<<"Enter Cache id: "; cin>>choice; (*bu).printHex(choice, (*bu).getPageSize()); break; case 13: (*bu).printCacheHeaders(); break; case 14: hr = (*bu).getHitRate(); if(hr!=-1) cout<<endl<<"\tHit rate is: "<<hr*100.0<<" %"<<endl; else { cout<<endl<<"\tHit rate cannot be calculated because cache"; cout<<" is either not initialized, or no operation"; cout<<" has been performed on cache yet."<<endl; } break; case 15: // releaseCache(bu); break; } }
Index build (char *dbname, int n, int *argc, char ***argv) { vpt *tree; int i, j; Tod *od; int nobjs; if (*argc < 1) { fprintf (stderr,"Usage: <program> <args> BUCKET-SIZE\n"); exit(1); } tree = malloc (sizeof(vpt)); tree->descr = malloc (strlen(dbname)+1); strcpy (tree->descr,dbname); tree->bsize = atoi((*argv)[0]); (*argc) -= 1; (*argv) += 1; nobjs = openDB(dbname); if (n && (n < nobjs)) nobjs = n; od = malloc (nobjs * sizeof (Tod)); j=0; i=0; while (j < nobjs) { od[i].tdist = 0; j++; od[i++].obj = j; } tree->node = buildvpt (tree,od,nobjs); free (od); prnstats((Index)tree); return (Index)tree; }
void DatabaseManager::setUpDB() { if (openDB()) { // check whether db is empty, if it is, create db if (m_db.tables().size() == 0) { createDB(); } else { QSqlQuery query(m_db); query.exec("SELECT name, version FROM information;"); if (query.isSelect()) { while (query.next()) { QString name = query.value(0).toString(); double version = query.value(1).toDouble(); qDebug() << "App name: " << name; qDebug() << "Database version : " << version; if (version == 1.0) { qDebug() << "Needs first update. Add the Banner table to db"; if (createBannerTable()) { updateInfoTable(2.0); } } } } } } }
int main(int argc, char **argv){ sqlite3 *db; char sqlStatement[500]; int i; if( argc!=2 ){ fprintf(stderr, "Usage: %s DATABASE\n", argv[0]); exit(1); } /* open the db, exit if error */ openDB(&db, argv[1]); //sendSql(db, "PRAGMA journal_mode=DELETE;"); //sendSql(db, "PRAGMA synchronous=OFF;"); /* create a table */ sendSql(db, "create table if not exists DAE(id integer not null, value real not null);"); /* delete the values */ sendSql(db, "delete from DAE;"); /* do a stress test */ sendSql(db, "begin transaction;"); for (i=0; i <= MAX; i++) { sprintf(sqlStatement, "insert into DAE values(%d, %g);", i, (double)i); sendSql(db, sqlStatement); } sendSql(db, "end transaction;"); sendSql(db, "select max(value) from DAE;"); sqlite3_close(db); return 0; }
spatialite_database_unique_ptr QgsAuxiliaryStorage::open( const QString &filename ) { spatialite_database_unique_ptr database; if ( filename.isEmpty() ) { if ( ( database = createDB( currentFileName() ) ) ) mValid = true; } else if ( QFile::exists( filename ) ) { if ( mCopy ) QFile::copy( filename, mTmpFileName ); if ( ( database = openDB( currentFileName() ) ) ) mValid = true; } else { if ( ( database = createDB( currentFileName() ) ) ) mValid = true; } return database; }
bool DbNote::existCategory(Category & category) { sqlite3_stmt *statement; string stmnt = "select count(*) from KatTable where KatDesc like ? or KatKey = ?"; if (!openDB()) { throw SQLError("Can't open the DB-Connection"); return false; } int req = sqlite3_prepare_v2(db, stmnt.c_str(), -1, &statement, 0); if (req != SQLITE_OK) { throw SQLError("Preparing Select-Statement failed in existCategory()"); return false; } req = sqlite3_bind_text(statement, 1, category.getDesc().c_str(), category.getDesc().size(), 0 ); req = sqlite3_bind_int(statement, 2, category.getKatKey()); if (req != SQLITE_OK) { throw SQLError("Binding Date into select statement failed"); return false; } req = sqlite3_step(statement); int catCount = static_cast<int>(sqlite3_column_int(statement, 0)); sqlite3_finalize(statement); sqlite3_close(db); if (catCount > 0) return true; return false; }
int DocumentDatabase::insertDocument(std::string Author, std::string Title, std::string PublishDate) { sqlite3* db = openDB(); int documentID = getDocumentID(db,Author, Title); if (documentID == -1) { int styleID = getStyleID(db,Author); if (styleID == -1) { styleID = insertStyle(db,Author); documentID = insertDocument(db, styleID, Title, PublishDate); //documentID = getDocumentID(Author, Title); } else { documentID = insertDocument(db,styleID, Title, PublishDate); //documentID = getDocumentID(Author, Title); } } else { // Just Return DocumentID } close(db); return documentID; }
DatabaseManager::DatabaseManager(QObject *parent) : QObject(parent) { openDB(); enumPrioridad << "Alta" << "Normal" << "Baja"; enumBalanzaSize << "Chica" << "Mediana" << "Grande" << "Vascula"; //Importante que esten ordenadas de menor a mayor }
bool DbNote::deleteRow(string sqlStmnt) { sqlite3_stmt *statement; if (!openDB()) { throw SQLError("Can't open the DB-Connection"); return false; } int req = sqlite3_prepare_v2(db, sqlStmnt.c_str(), sqlStmnt.length(), &statement, 0); if (req != SQLITE_OK) { throw SQLError("Preparing Delete-Statement failed"); return false; } req = sqlite3_step(statement); if (req != SQLITE_DONE) { throw SQLError("execute of delete statement failed"); return false; } sqlite3_finalize(statement); sqlite3_close(db); return true; }
bool DbNote::existNote(Note & note) { sqlite3_stmt *statement; string stmnt = "select count(*) from NoteTable where NoteKey = ?"; if (!openDB()) { throw SQLError("Can't open the DB-Connection"); return false; } int req = sqlite3_prepare_v2(db, stmnt.c_str(), -1, &statement, 0); if (req != SQLITE_OK) { throw SQLError("Preparing select-Statement failed"); return false; } req = sqlite3_bind_int(statement, 1, note.getNoteKey()); if (req != SQLITE_OK) { throw SQLError("Binding Date into select statement failed"); return false; } req = sqlite3_step(statement); int noteCount = static_cast<int>(sqlite3_column_int(statement, 0)); sqlite3_finalize(statement); sqlite3_close(db); if (noteCount > 0) return true; return false; }
void MainWindow::on_pushButton_clicked() //search { openDB(); QSqlQuery query; query.prepare("select title, new_name, price, ISBN, 'Add to cart' from " "( " "select row_number() over(order by title) NUM, title, new_name, price, ISBN, 'Add to cart' from " "( " "select title, wm_concat(a.name) as new_name, price, b.ISBN, 'Add to cart' " "from BOOK b INNER JOIN BOOK_S_AUTHOR ba on b.ISBN = ba.ISBN INNER JOIN AUTHOR a on ba.author_id = a.author_id " "where (lower(b.title) LIKE lower(:search1)) or (lower(a.name) LIKE lower(:search2)) or (lower(b.isbn) LIKE lower(:search3)) " "group by title, price, b.ISBN " ") asdf " ") foo where Num>:lowvalue and Num<:highvalue"); QString searchCriteria(ui->lineEdit->text()); searchCriteria = '%' + searchCriteria + '%'; qDebug()<<"What to search?: "<<searchCriteria; query.bindValue(":search1", searchCriteria); query.bindValue(":search2", searchCriteria); query.bindValue(":search3", searchCriteria); query.bindValue(":lowvalue", current_book_page*10); query.bindValue(":highvalue", 10+current_book_page*10); qDebug()<<"search query: "<<query.exec(); qDebug()<<query.lastError(); booksModel->setQuery(query); qDebug()<<"rows count: "<<booksModel->rowCount(); closeDB(); }
Index loadIndex(char *fname) { FURTHEST_INDEX *fi; FILE *ifile; fi=(FURTHEST_INDEX *)malloc(sizeof(FURTHEST_INDEX)); ifile=fopen(fname,"rb"); if (ifile==NULL) { fprintf(stderr,"Error opening index file.\n"); exit(1); } if (fread(fi,sizeof(int),5,ifile)!=5) { fprintf(stderr,"Error reading index header.\n"); exit(1); } if (fi->magic!=MAGIC) { fprintf(stderr,"Bad magic number in index file.\n"); exit(1); } fprintf(stderr, "Reading index for %d points, %d dimensions, " "%d projections, %s.\n", fi->num_points,fi->num_dimensions,fi->num_projections, algoname[fi->algorithm]); fi->dbname=(char *)malloc(201); if (fgets(fi->dbname,201,ifile)<0) { fprintf(stderr,"Error reading database name.\n"); exit(1); } fi->dbname[strlen(fi->dbname)-1]='\0'; fi->pdp=(PDIST_PAIR *)malloc(sizeof(PDIST_PAIR)* (fi->num_projections+1)*fi->num_points); if (fread(fi->pdp,sizeof(PDIST_PAIR), (fi->num_projections+1)*fi->num_points, ifile) !=(fi->num_projections+1)*fi->num_points) { fprintf(stderr,"Error %d reading permutations.\n",errno); exit(1); } fi->projections=(float *)malloc(sizeof(float)* fi->num_projections*fi->num_dimensions); if (fread(fi->projections,sizeof(float), fi->num_projections*fi->num_dimensions,ifile) !=fi->num_projections*fi->num_dimensions) { fprintf(stderr,"Error %d reading projection vectors.\n",errno); exit(1); } fclose(ifile); openDB(fi->dbname); return (Index)fi; }
void MainWindow::openFile(const QString &file) { QFileInfo file_info(file); if (file_info.exists() && !saveChangesBeforeProceeding(tr("Open database"), true)) { addRecent(file_info.absoluteFilePath()); openDB(file_info.absoluteFilePath()); } }
int BufferManager::expandDB(int mdtID, long size){ int dbStatus = closeDB(mdtID); if( dbStatus == 1 || dbStatus == -2){ mdtID=openDB(mdt[mdtID].dbPath, mdt[mdtID].dbName); if(mdt[mdtID].isopen){ mdt[mdtID].fd.seekp(1, ios::end); for(int i=0; i<(size-1); i++){ mdt[mdtID].fd.write("", 1); } closeDB(mdtID); mdtID = openDB(mdt[mdtID].dbPath, mdt[mdtID].dbName); } return mdtID; } else return dbStatus; }
void consume(const IMC::PlanDB* pdb) { if (pdb->op != IMC::PlanDB::DBOP_BOOT || pdb->type != IMC::PlanDB::DBT_SUCCESS) return; openDB(); }
LocationWatcher::LocationWatcher(QObject *parent) : QObject(parent) { openDB(); source = QGeoPositionInfoSource::createDefaultSource(this); setinterval(getSetting("time")); setgpsmode(getSetting("usegps")); }
/** * @brief Constructor. * Opens the Database. If empty, create the schema. */ DatabaseManager::DatabaseManager() { openDB(); createTables(); m_moviesPathModel = new QStringListModel(); }
bool QgsStyleV2::load( QString filename ) { mErrorString.clear(); // Open the sqlite database if ( !openDB( filename ) ) { mErrorString = "Unable to open database file specified"; QgsDebugMsg( mErrorString ); return false; } // First create all the main symbols const char *query = "SELECT * FROM symbol"; sqlite3_stmt *ppStmt; int nError = sqlite3_prepare_v2( mCurrentDB, query, -1, &ppStmt, NULL ); while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW ) { QDomDocument doc; QString symbol_name = QString::fromUtf8(( const char * ) sqlite3_column_text( ppStmt, SymbolName ) ); QString xmlstring = QString::fromUtf8(( const char * ) sqlite3_column_text( ppStmt, SymbolXML ) ); if ( !doc.setContent( xmlstring ) ) { QgsDebugMsg( "Cannot open symbol " + symbol_name ); continue; } QDomElement symElement = doc.documentElement(); QgsSymbolV2 *symbol = QgsSymbolLayerV2Utils::loadSymbol( symElement ); if ( symbol != NULL ) mSymbols.insert( symbol_name, symbol ); } sqlite3_finalize( ppStmt ); const char *rquery = "SELECT * FROM colorramp"; nError = sqlite3_prepare_v2( mCurrentDB, rquery, -1, &ppStmt, NULL ); while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW ) { QDomDocument doc; QString ramp_name = QString::fromUtf8(( const char * ) sqlite3_column_text( ppStmt, ColorrampName ) ); QString xmlstring = QString::fromUtf8(( const char * ) sqlite3_column_text( ppStmt, ColorrampXML ) ); if ( !doc.setContent( xmlstring ) ) { QgsDebugMsg( "Cannot open symbol " + ramp_name ); continue; } QDomElement rampElement = doc.documentElement(); QgsVectorColorRampV2 *ramp = QgsSymbolLayerV2Utils::loadColorRamp( rampElement ); if ( ramp ) mColorRamps.insert( ramp_name, ramp ); } mFileName = filename; return true; }
bool DbNote::insertTable(Category & cat) { sqlite3_stmt *statement; string stmnt = "insert into KatTable (KatDesc) values (?)"; if (!openDB()) { throw SQLError("Can't open the DB-Connection"); return false; } int req = sqlite3_prepare_v2(db, stmnt.c_str(), stmnt.length(), &statement, 0); if (req != SQLITE_OK) { throw SQLError("Preparing Insert-Statement failed"); return false; } req = sqlite3_bind_text(statement, 1, (cat.getDesc()).c_str(), (cat.getDesc()).length(), SQLITE_TRANSIENT); if (req != SQLITE_OK) { throw SQLError( "Binding category descripting into insert statement failed"); return false; } req = sqlite3_step(statement); if (req != SQLITE_DONE) { throw SQLError("execute of insert statement failed"); return false; } sqlite3_finalize(statement); stmnt = "select seq from sqlite_sequence where name = \"KatTable\""; req = sqlite3_prepare_v2(db, stmnt.c_str(), stmnt.length(), &statement, 0); if (req == SQLITE_ERROR) { throw SQLError("Can't select data of the given table"); return false; } sqlite3_column_count(statement); req = sqlite3_step(statement); if (req == SQLITE_ROW) { int nextseq = (int) sqlite3_column_int(statement, 0); cat.setKatKey( nextseq ); } else { throw SQLError("execute of select failed"); return false; } sqlite3_finalize(statement); sqlite3_close(db); return true; }
// Migrate the database int migrate(char* dbPath, CK_SLOT_ID slotID, char* userPIN, int noPublicKey) { CK_SESSION_HANDLE hSession; sqlite3* db = NULL; int result; if (dbPath == NULL) { fprintf(stderr, "ERROR: A path to the database must be supplied. " "Use --db <path>\n"); return 1; } // Open the database db = openDB(dbPath); if (db == NULL) { return 1; } // Connect to the PKCS#11 library result = openP11(slotID, userPIN, &hSession); if (result) { sqlite3_close(db); return result; } // Prepare the statements if (prepStatements(db)) { fprintf(stderr, "ERROR: Could not prepare the statements\n"); finalStatements(); sqlite3_close(db); return 1; } // Start the migration result = db2session(db, hSession, noPublicKey); // Finalize the statements finalStatements(); sqlite3_close(db); if (result) { fprintf(stderr, "ERROR: Unable to migrate all of the objects.\n"); } else { printf("The database has been migrated to the new HSM\n"); } return result; }