/*--------------------------------------------------------------------- * M A I N P R O G R A M *---------------------------------------------------------------------*/ int main(int argc, char **argv) { params_t oci_params; /* Outbound connection info */ conn_info_t xout_params = {XOUT_USER, XOUT_USER_LEN, XOUT_PSW, XOUT_PSW_LEN, XOUT_DB, XOUT_DB_LEN, XOUT_APPLY, XOUT_APPLY_LEN}; /* Database connection info */ conn_info_t db_params = {DB_USER, DB_USER_LEN, DB_PSW, DB_PSW_LEN, XOUT_DB, XOUT_DB_LEN, (oratext *) 0, 0}; myctx_t ctx; oci_t *ocip = (oci_t *)NULL; ub2 obdb_char_csid = 0; /* outbound db char csid */ ub2 obdb_nchar_csid = 0; /* outbound db nchar csid */ memset(&ctx, 0, sizeof(ctx)); ctx.longform = TRUE; /* parse command line arguments */ get_inputs(&ctx, &xout_params, &db_params, argc, argv); /* Get the outbound database CHAR and NCHAR character set info */ get_db_charsets(&xout_params, &obdb_char_csid, &obdb_nchar_csid); /* connect to the source database */ connect_db(&xout_params, &ocip, obdb_char_csid, obdb_nchar_csid); /* Attach to outbound server */ attach_session(ocip, &xout_params, TRUE); ctx.outbound_ocip = ocip; /* connect to source database to do query and inserts on source tables */ ocip = (oci_t *)NULL; connect_db(&db_params, &ocip, obdb_char_csid, obdb_nchar_csid); ctx.sql_sel_ocip = ocip; /* Get lcrs from outbound server and send to inbound server */ get_lcrs(&ctx); /* Detach from XStream servers */ detach_session(ctx.outbound_ocip, FALSE); /* Disconnect from outbound database */ disconnect_db(ctx.outbound_ocip); free(ctx.outbound_ocip); /* Disconnect from sql database */ disconnect_db(ctx.sql_sel_ocip); free(ctx.sql_sel_ocip); return 0; }
int atualizar(cliente c) { sql_update = "UPDATE clientes SET nome_cliente = ?, localizacao = ?, email = ?, aniversario = ?, link = ? WHERE id_cliente = ?;"; int r = connect_db(); if (r != SQLITE_OK) { fprintf(stderr, "Erro ao conectar com o banco de dados!! %s\n", sqlite3_errmsg(conn)); close_db(); return 0; } else { msg = sqlite3_exec(conn, sql_update, callback, 0, &errMsg); if (msg != SQLITE_OK) { fprintf(stderr, "Não foi possivel executar comando!! %s\n", errMsg); close_db(); return 0; } else { sqlite3_bind_text(stmt, 1, c.nome_cliente, strlen(c.nome_cliente), 0); sqlite3_bind_text(stmt, 2, c.localizacao, strlen(c.localizacao), 0); sqlite3_bind_text(stmt, 3, c.email, strlen(c.email), 0); sqlite3_bind_text(stmt, 4, c.aniversario, strlen(c.aniversario), 0); sqlite3_bind_text(stmt, 5, c.link, strlen(c.link), 0); sqlite3_bind_int(stmt, 6, c.id_cliente); } close_db(); return 1; } }
static boolean authority_synchronization_main(SSL *ssl_client, unsigned int authority_id, char *authority_name) { MYSQL *db_conn = NULL; // Connect the database connect_db(&db_conn, DB_IP, DB_USERNAME, DB_PASSWD, DB_NAME); if(!synchronize_authority_info(ssl_client)) goto ERROR; if(!synchronize_attribute(db_conn, ssl_client)) goto ERROR; if(!synchronize_user(db_conn, ssl_client)) goto ERROR; if(!synchronize_access_permission(db_conn, ssl_client, authority_id)) goto ERROR; if(!synchronize_emergency_delegation(ssl_client, authority_name)) goto ERROR; if(!synchronize_phr_transaction_log(ssl_client, authority_name)) goto ERROR; disconnect_db(&db_conn); return true; ERROR: disconnect_db(&db_conn); return false; }
bool Server::connect_router_after() { bind_and_connect(); connect_login(); connect_db(); return true; }
static void load_user_basic_info(char *username, boolean is_admin_flag, char *email_address_ret) { MYSQL *db_conn = NULL; MYSQL_RES *result = NULL; MYSQL_ROW row; char stat[SQL_STATEMENT_LENGTH + 1]; char err_msg[ERR_MSG_LENGTH + 1]; // Connect the database connect_db(&db_conn, DB_IP, DB_USERNAME, DB_PASSWD, DB_NAME); // Query the user's e-mail address sprintf(stat, "SELECT email_address FROM %s WHERE username LIKE '%s' COLLATE latin1_general_cs", (is_admin_flag) ? UA__ADMINS : UA__USERS, username); if(mysql_query(db_conn, stat)) { sprintf(err_msg, "Error %u: %s\n", mysql_errno(db_conn), mysql_error(db_conn)); int_error(err_msg); } result = mysql_store_result(db_conn); row = mysql_fetch_row(result); if(!row) int_error("Getting user basic information from the database failed"); strcpy(email_address_ret, row[0]); if(result) { mysql_free_result(result); result = NULL; } disconnect_db(&db_conn); }
void Server::connect_db() { ip::tcp::resolver resolver(m_io_service); ip::tcp::resolver::iterator it = resolver.resolve( {"127.0.0.1", "12000"} ); m_db_conn.reset(new DBSvrConn(m_io_service)); async_connect(m_db_conn->socket(), it, [this] (const err_code& ec, ip::tcp::resolver::iterator it_) { if (!ec) { cout << "connected DbSvr!" << endl; int id = allocate_conn_id(); m_db_conn->connect(id); } else { cout << "error. try connect db..." << endl; boost::asio::deadline_timer t(m_io_service, boost::posix_time::seconds(10)); t.wait(); connect_db(); } }); }
QStringList record::read_db(){ if (!connect_db()) return QStringList(); //return empty string int rc=0, rc1=0; QStringList result; sqlite3_stmt *pStmt=0; const char *zTail; do{ rc1 = sqlite3_prepare_v2(db, "SELECT * FROM Filelist;", -1, &pStmt, &zTail); if (rc1 != SQLITE_OK){ emit kiwiError(Q_FUNC_INFO, tr("sqlite3_prepare_v2 fail!(%1,%2)").arg(rc1).arg(sqlite3_errmsg(db))); rc = KiwiSQLitePrepareError; break; } if (!pStmt){ emit kiwiError(Q_FUNC_INFO, tr("statement handle is null!")); rc = KiwiSQLiteStatementNULL; break; } do{ rc1 = sqlite3_step(pStmt); if (rc1 == SQLITE_DONE){ //result = "(not-found)"; break; } if (rc1 != SQLITE_ROW){ emit kiwiError(Q_FUNC_INFO, tr("result not ready!")); rc = KiwiSQLiteResultNotReady; break; } for(int i=0;i<2;i++){ char* s=(char*)sqlite3_column_text(pStmt,i); result.append(QString::fromUtf8(s)); } }while(rc1 != SQLITE_DONE); return result; //char *s = (char*)sqlite3_column_text(pStmt, 0); /* if (!s){ emit kiwiError(Q_FUNC_INFO, tr("cacheFileDir is null!")); rc = 10; break; } */ //result = QStringList(s); }while(0); if (pStmt) sqlite3_finalize(pStmt); pStmt = 0; return result; /* int rows=0,cols=0; char** result,*errMsg; QString querysql = "SELECT * FROM Filelist;"; sqlite3_get_table(db , querysql.toLatin1(), &result , &rows, &cols, &errMsg); return *result; */ }
/* * mysql_safe_query() * * Sanitizes Sql Querys */ int mysql_safe_query (char *query) { char buf[4*MAX_STRING_LENGTH]; buf[0] = '\0'; if( !db_connect ) connect_db(); if( &db == NULL ) { log_string(LOG_SQL,"NULL db in query_db."); return 0; } if( query == NULL || query[0] == '\0') { log_string(LOG_SQL,"Null query in query_db()"); return 0; } if (mysql_real_query(&db, query, strlen(query))) { //log_string(LOG_SQL,"query_db(): error on query"); sprintf(buf,"Error: %s", mysql_error(&db)); log_string(LOG_SQL,buf); return 0; } return 1; }
db_con_t *db_init(const char* _sqlurl) { db_con_t* res; void* t; DLOG("db_init", "entry"); /* ** this is the root memory for this database connection. */ res = aug_alloc(sizeof(db_con_t), 0); memset(res, 0, sizeof(db_con_t)); t = aug_alloc(sizeof(struct con_postgres), (char*)res); res->tail = (unsigned long) t; memset((struct con_postgres*)res->tail, 0, sizeof(struct con_postgres)); if (connect_db(res, _sqlurl) < 0) { PLOG("db_init", "Error while trying to open database, FATAL\n"); aug_free(res); return((db_con_t *) 0); } return res; }
int inserir(cliente c) { char sql_insert = "INSERT INTO clientes VALUES(?, ?, ?, ?, ?, ?, ?, ?);"; int r = connect_db(); if (r != SQLITE_OK) { fprintf(stderr, "Erro ao conectar com o banco de dados!! %s\n", sqlite3_errmsg(conn)); close_db(); return 0; } else { msg = sqlite3_exec(conn, sql_insert, callback, 0, &errMsg); if (msg != SQLITE_OK) { fprintf(stderr, "Não foi possivel executar comando!! %s\n", errMsg); close_db(); return 0; } else { sqlite3_bind_null(stmt, 1); sqlite3_bind_int(stmt, 2, c.id_cliente); sqlite3_bind_text(stmt, 3, c.nome_cliente, strlen(c.nome_cliente), 0); sqlite3_bind_text(stmt, 4, c.localizacao, strlen(c.localizacao), 0); sqlite3_bind_text(stmt, 5, c.email, strlen(c.email), 0); sqlite3_bind_text(stmt, 6, c.aniversario, strlen(c.aniversario), 0); sqlite3_bind_text(stmt, 7, c.link, strlen(c.link), 0); } close_db(); return 1; } }
int main(int argc, char *argv[]) { if(argc <= 1){ show_usage(); return 0; } //surpress stderr, because dblib.c display ugly error message freopen("/dev/null", "w", stderr); dbinfo = (struct dbconfig *)malloc(sizeof(struct dbconfig)); if (!set_cmd_option( argc, argv, dbinfo)){ return 0; } if (!connect_db(dbinfo)){ return 0; } //set hisotry file path history_file = (char *)malloc(256); strcpy(history_file, getenv("HOME")); strcat(history_file, MSSQL_HISTORY_FILE_NAME); read_history(history_file); //read history for incremental search (ctrl + r) rl_startup_hook = my_startup; //set up readline with original method binding my_readline(); }
static int child_init(int rank) { /* Check if database is needed by child */ if (rank > 0 || rank == PROC_RPC || rank == PROC_UNIXSOCK) { if (connect_db() < 0) return -1; } return 0; }
static int open_connections (const char *path_origin, const char *path_destination, void *cache_in, void *cache_out, sqlite3 ** xhandle_in, sqlite3 ** xhandle_out) { /* establishing IN and OUT DB connections */ sqlite3 *handle_in = NULL; sqlite3 *handle_out = NULL; if (already_existing (path_destination)) { fprintf (stderr, "Already existing output destination:\n\"%s\"\n", path_destination); return 0; } /* attempting to connect the IN DB */ handle_in = connect_db (path_origin, SQLITE_OPEN_READONLY, cache_in); if (handle_in == NULL) goto error; /* attempting to connect the OUT DB */ handle_out = connect_db (path_destination, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, cache_out); if (handle_out == NULL) goto error; *xhandle_in = handle_in; *xhandle_out = handle_out; return 1; error: if (handle_in != NULL) sqlite3_close (handle_in); if (handle_out != NULL) sqlite3_close (handle_out); return 0; }
static boolean authority_exists(char *authority_name, unsigned int *authority_id_ret) { MYSQL *db_conn = NULL; MYSQL_RES *result = NULL; MYSQL_ROW row; char stat[SQL_STATEMENT_LENGTH + 1]; char err_msg[ERR_MSG_LENGTH + 1]; // Connect the database connect_db(&db_conn, DB_IP, DB_USERNAME, DB_PASSWD, DB_NAME); // Query for authority info sprintf(stat, "SELECT authority_id FROM %s WHERE authority_name LIKE '%s' COLLATE latin1_general_cs", UA__AUTHORITIES, authority_name); if(mysql_query(db_conn, stat)) { sprintf(err_msg, "Error %u: %s\n", mysql_errno(db_conn), mysql_error(db_conn)); int_error(err_msg); } result = mysql_store_result(db_conn); row = mysql_fetch_row(result); if(!row) { goto ERROR; } *authority_id_ret = atoi(row[0]); if(result) { mysql_free_result(result); result = NULL; } disconnect_db(&db_conn); return true; ERROR: if(result) { mysql_free_result(result); result = NULL; } disconnect_db(&db_conn); return false; }
bool record::create_tbl(){ ColumnDef_t columns; if (!connect_db()) return false; int rc=exec_SQL(db,"CREATE TABLE IF NOT EXISTS Filelist ( name text, path text )"); if (rc != SQLITE_OK){ emit kiwiError(Q_FUNC_INFO, tr("open db fail(%1,%2)").arg(rc).arg(sqlite3_errmsg(db))); return false; } else{ emit kiwiLog(Q_FUNC_INFO, tr("open db ok")); return true; } }
int test_db_connection(char *database_name){ PGconn *conn; conn = connect_db(database_name); if (PQstatus(conn) != CONNECTION_OK) { close_db(conn); return(1); } else { printf("Connection to database successful! Will use database for storage of data.\n"); } close_db(conn); return(0); }
/** * Seleciona o cliente pelo id passado nos parâmetros. * @param id_cliente id do cliente no banco de dados. * @return */ int cliente_by_id(int id_cliente) { char sql = "SELECT * FROM clientes WHERE id_cliente = ?;"; if (connect_db() == 0) { sqlite3_prepare_v2(conn, sql, -1, &stmt, NULL); sqlite3_bind_text(stmt, 1, id_cliente, strlen(id_cliente), 0); if (sqlite3_step(stmt) == SQLITE_ROW) { int aux = atoi((char*) sqlite3_column_text(stmt, 0)); sqlite3_finalize(stmt); close_db(); return aux; } else return -1; } else { fprintf(stderr, "Não foi possível abrir o banco de dados: %s\n", sqlite3_errmsg(conn)); return -1; } }
int main(int argc , char * argv[]) { int status; char * str_err_msg= NULL; db_report = stdout; printf("sqlite version : %s\n%s\n",sqlite3_libversion(),sqlite3_sourceid()); //_hdb db; connect_db("demo.db"); // /** PREPARE("create table usrpwd(usr QString, pwd QString)"); status = sqlite3_exec(db, QUERY, 0, 0, &str_err_msg); printf("c->status: %d ~ %s \n",status,str_err_msg); /* */ // /** PREPARE("insert into usrpwd values('hkkk','khhh')"); status = sqlite3_exec(db, QUERY, 0, 0, &str_err_msg); printf("c->status: %d ~ %s \n",status,str_err_msg); //**/ PREPARE("select * from usrpwd "); status = sqlite3_exec(db, QUERY, result_handle, // int (*callback)(void*,int,char**,char**), 0, &str_err_msg); printf("c->status: %d ~ %s \n",status,str_err_msg); status = sqlite3_close(db); if(status != SQLITE_OK ) printf("error:%d\n",sqlite3_errcode(db)); printf("%s",sqlite3_mprintf("%q","it's example")); return 0; }
//**** Add a record to database**** int record::add_db(QString name,QString path){ if (!connect_db()) return -1; int rc=0, rc1; sqlite3_stmt *pStmt=0; const char *zTail; do{ rc1 = sqlite3_prepare_v2(db, "insert into Filelist(name,path) values (:name, :path)", -1, &pStmt, &zTail); if (rc1 != SQLITE_OK){ emit kiwiError(Q_FUNC_INFO, tr("sqlite3_prepare_v2 fail!(%1,%2)").arg(rc1).arg(sqlite3_errmsg(db))); rc=KiwiSQLitePrepareError; break; } if (!pStmt){ emit kiwiError(Q_FUNC_INFO, tr("statement handle is null!")); rc=KiwiSQLiteStatementNULL; break; } rc1 = sqlite3_bind_text(pStmt, 1, name.toUtf8().data(), -1, SQLITE_TRANSIENT); if (rc1 != SQLITE_OK){ emit kiwiError(Q_FUNC_INFO, tr("bind column 'name' fail!(%1,%2)").arg(rc1).arg(sqlite3_errmsg(db))); rc=KiwiSQLiteBindFail; break; } rc1 = sqlite3_bind_text(pStmt, 2, path.toUtf8().data(), -1, SQLITE_TRANSIENT); if (rc1 != SQLITE_OK){ emit kiwiError(Q_FUNC_INFO, tr("bind column 'path' fail!(%1,%2)").arg(rc1).arg(sqlite3_errmsg(db))); rc=KiwiSQLiteBindFail; break; } rc1 = sqlite3_step(pStmt); if (rc1 != SQLITE_DONE){ emit kiwiError(Q_FUNC_INFO, tr("sqlite3_step fail!(%1,%2)").arg(rc1).arg(sqlite3_errmsg(db))); rc=KiwiSQLiteExecuteFail; break; } }while(0); if (pStmt) sqlite3_finalize(pStmt); pStmt = 0; if (rc == 0) emit kiwiLog(Q_FUNC_INFO, tr("new map(%1): %2 ").arg(name).arg(path)); return (rc == 0); }
//**** Update record in the database **** bool record::update_db(QString old_name, QString new_name){ if (!connect_db()) return false; int rc=0, rc1; sqlite3_stmt *pStmt=0; const char *zTail; do{ rc1 = sqlite3_prepare_v2(db, "update Filelist set name=:new_name where name=:old_name", -1, &pStmt, &zTail); if (rc1 != SQLITE_OK){ emit kiwiError(Q_FUNC_INFO, tr("sqlite3_prepare_v2 fail!(%1,%2)").arg(rc1).arg(sqlite3_errmsg(db))); rc=KiwiSQLitePrepareError; break; } if (!pStmt){ emit kiwiError(Q_FUNC_INFO, tr("statement handle is null!")); rc=KiwiSQLiteStatementNULL; break; } rc1 = sqlite3_bind_text(pStmt, 1, new_name.toUtf8().data(), -1, SQLITE_TRANSIENT); if (rc1 != SQLITE_OK){ emit kiwiError(Q_FUNC_INFO, tr("bind 'new_name' fail!(%1,%2)").arg(rc1).arg(sqlite3_errmsg(db))); rc=KiwiSQLiteBindFail; break; } rc1 = sqlite3_bind_text(pStmt, 2, old_name.toUtf8().data(), -1, SQLITE_TRANSIENT); if (rc1 != SQLITE_OK){ emit kiwiError(Q_FUNC_INFO, tr("bind 'old_name' fail!(%1,%2)").arg(rc1).arg(sqlite3_errmsg(db))); rc=KiwiSQLiteBindFail; break; } rc1 = sqlite3_step(pStmt); if (rc1 != SQLITE_DONE){ emit kiwiError(Q_FUNC_INFO, tr("sqlite3_step fail!(%1,%2)").arg(rc1).arg(sqlite3_errmsg(db))); rc=KiwiSQLiteExecuteFail; break; } }while(0); if (pStmt) sqlite3_finalize(pStmt); pStmt = 0; if (rc == 0) emit kiwiLog(Q_FUNC_INFO, tr("(%1): %2 ").arg(old_name).arg(new_name)); //return (rc == 0); }
static void set_authority_join_flag(unsigned int authority_id) { MYSQL *db_conn = NULL; char stat[SQL_STATEMENT_LENGTH + 1]; char err_msg[ERR_MSG_LENGTH + 1]; // Connect the database connect_db(&db_conn, DB_IP, DB_USERNAME, DB_PASSWD, DB_NAME); // Set the authority join flag sprintf(stat, "UPDATE %s SET authority_join_flag='1' WHERE authority_id=%u", UA__AUTHORITIES, authority_id); if(mysql_query(db_conn, stat)) { sprintf(err_msg, "Error %u: %s\n", mysql_errno(db_conn), mysql_error(db_conn)); int_error(err_msg); } disconnect_db(&db_conn); }
int add_user(char * username, char * password){ sqlite3 *db; int rc; char *insert_str = "INSERT INTO users (id, username, password )"\ "VALUES (NULL, :USER, :PASS);"; connect_db(db); sqlite3_stmt *insert_stmt; if((rc = sqlite3_prepare_v2(db, insert_str, sizeof(insert_str), &insert_stmt, NULL)) != SQLITE_OK){ fprintf(stderr, "SQLite error preparing insert statement: %s\n", sqlite3_errmsg(db)); sqlite3_close(db); exit(3); } if((rc = sqlite3_bind_text(insert_stmt, 2, username, sizeof(username), NULL)) != SQLITE_OK){ fprintf(stderr, "SQLite error binding username: %s\n", sqlite3_errmsg(db)); sqlite3_close(db); exit(3); } if((rc = sqlite3_bind_text(insert_stmt, 3, password, sizeof(password), NULL)) != SQLITE_OK){ fprintf(stderr, "SQLite error binding password: %s\n", sqlite3_errmsg(db)); sqlite3_close(db); exit(3); } if((rc = sqlite3_step(insert_stmt)) != SQLITE_DONE){ fprintf(stderr, "SQLite error inserting: %s\n", sqlite3_errmsg(db)); exit(3); } if((rc = sqlite3_reset(insert_stmt)) != SQLITE_OK){ fprintf(stderr, "SQLite error resetting: %s\n", sqlite3_errmsg(db)); exit(3); } if(rc = sqlite3_finalize(insert_stmt)){ fprintf(stderr, "Can't finalize statement: %s\n", sqlite3_errmsg(db)); exit(3); } }
static int child_init(int _rank) { dlist_t* ptr; /* connecting to DB ? */ switch (db_mode) { case NO_DB: return 0; case WRITE_THROUGH: /* connect to db only from SIP workers, TIMER and MAIN processes */ if (_rank<=0 && _rank!=PROC_TIMER && _rank!=PROC_MAIN) return 0; break; case WRITE_BACK: /* connect to db only from TIMER (for flush), from MAIN (for * final flush() and from child 1 for preload */ if (_rank!=PROC_TIMER && _rank!=PROC_MAIN && _rank!=PROC_SIPINIT) return 0; break; } LM_DBG("Connecting to usrloc_pcscf DB for rank %d\n", _rank); if (connect_db(&db_url) != 0) { LM_ERR("child(%d): failed to connect to database\n", _rank); return -1; } /* _rank==PROC_SIPINIT is used even when fork is disabled */ if (_rank==PROC_SIPINIT && db_mode!=DB_ONLY) { // if cache is used, populate domains from DB for( ptr=root ; ptr ; ptr=ptr->next) { LM_DBG("Preloading domain %.*s\n", ptr->name.len, ptr->name.s); if (preload_udomain(ul_dbh, ptr->d) < 0) { LM_ERR("child(%d): failed to preload domain '%.*s'\n", _rank, ptr->name.len, ZSW(ptr->name.s)); return -1; } } } return 0; }
/* this is the main body */ int main(int argc, char *argv[]) { if (cfg.verbose) printf("%s version %s\n", APPNAME, VERSION); /* fill the cfg struct with the default options */ fill_default_options(); /* parse options from config file */ parse_cfgfile(cfg.cfgfile); /* parse the command line options */ parse_opts(argc, argv); odbc_alloc(); connect_db(cfg.dsn, cfg.dbuser, cfg.dbpass); get_embedded_infos(); disconnect_db(); /* if cfg.daemon option is set to 1 we go to background */ if (cfg.daemon) daemon(0, 0); /* set signal hook function */ signal(SIGHUP, &destroyall); signal(SIGINT, &destroyall); signal(SIGQUIT, &destroyall); signal(SIGTERM, &destroyall); signal(SIGABRT, &destroyall); /* open and configure the serial port */ cfgport(); /* enter the main loop */ serial_mainloop(); odbc_free(); disconnect_db(); free_cfg(); free_emb_info(); exit(0); }
int listar() { sql_query = "SELECT * FROM clientes;"; int r = connect_db(); if (r != SQLITE_OK) { fprintf(stderr, "Erro ao conectar com o banco de dados!! %s\n", sqlite3_errmsg(conn)); close_db(); return 0; } else { msg = sqlite3_exec(conn, sql_query, callback, 0, &errMsg); if (msg != SQLITE_OK) { fprintf(stderr, "Não foi possivel executar comando!! %s\n", errMsg); close_db(); return 0; } close_db(); return 1; } }
int start_transaction() { state = INIT; connect_db(); while (true) { Request * request = get_request(); switch(request->cmd) { case LOGIN: login(request); break; case REGISTER: register_u(request); break; case QUIT: fprintf(stderr, "QUIT\n"); state = IDLE; close_db(); return 0; case QUERY_STATIONS: query_stations(); break; case QUERY_TRAIN: query_train(request); break; case BUY_IT: buy_it(request); break; case QUERY_ORDERS: query_orders(); break; case REFUND: refund_orders(request); break; default: break; } } return 0; }
bool record::remove_record(QString path){ if (!connect_db()) return -1; int rc=0, rc1; sqlite3_stmt *pStmt=0; const char *zTail; do{ rc1 = sqlite3_prepare_v2(db, "delete from Filelist where path=:path", -1, &pStmt, &zTail); if (rc1 != SQLITE_OK){ emit kiwiError(Q_FUNC_INFO, tr("sqlite3_prepare_v2 fail!(%1,%2)").arg(rc1).arg(sqlite3_errmsg(db))); rc=KiwiSQLitePrepareError; break; } if (!pStmt){ emit kiwiError(Q_FUNC_INFO, tr("statement handle is null!")); rc=KiwiSQLiteStatementNULL; break; } rc1 = sqlite3_bind_text(pStmt, 1, path.toLatin1().data(), -1, SQLITE_TRANSIENT); if (rc1 != SQLITE_OK){ emit kiwiError(Q_FUNC_INFO, tr("bind column 'name' fail!(%1,%2)").arg(rc1).arg(sqlite3_errmsg(db))); rc=KiwiSQLiteBindFail; break; } rc1 = sqlite3_step(pStmt); if (rc1 != SQLITE_DONE){ emit kiwiError(Q_FUNC_INFO, tr("sqlite3_step fail!(%1,%2)").arg(rc1).arg(sqlite3_errmsg(db))); rc=KiwiSQLiteExecuteFail; break; } }while(0); if (pStmt) sqlite3_finalize(pStmt); pStmt = 0; if (rc == 0) emit kiwiLog(Q_FUNC_INFO, tr(" record:(%1)deleted.").arg(path)); return (rc == 0); }
int deletar(int id_cliente) { sql_delete = "DELETE FROM clientes WHERE id_cliente = ?;"; int r = connect_db(); if (r != SQLITE_OK) { fprintf(stderr, "Erro ao conectar com o banco de dados!! %s\n", sqlite3_errmsg(conn)); close_db(); return 0; } else if (cliente_by_id(id_cliente)) { msg = sqlite3_prepare_v2(conn, sql_delete, -1, &stmt, 0); if (msg != SQLITE_OK) { fprintf(stderr, "Não foi possivel executar comando!! %s\n", errMsg); close_db(); return 0; } else { sqlite3_bind_int(stmt, 1, id_cliente); return 1; } close_db(); } return 1; }
static int mod_init(void) { if (bind_dbmod(db_url.s, &db )) { LOG(L_CRIT, "Cannot bind to database module! " "Did you forget to load a database module ?\n"); return -1; } /* Check if cache needs to be loaded from domain table */ if (db_mode) { if (connect_db() < 0) goto error; if (check_version() < 0) goto error; if (allocate_tables() < 0) goto error; if (reload_domain_list() < 0) goto error; disconnect_db(); } return 0; error: disconnect_db(); return -1; }
int init_db(const str *db_url, int db_update_period, int fetch_num_rows) { /* Find a database module */ if (db_bind_mod(db_url, &ul_dbf) < 0){ LM_ERR("Unable to bind to a database driver\n"); return -1; } if (connect_db(db_url)!=0){ LM_ERR("unable to connect to the database\n"); return -1; } if (!DB_CAPABILITY(ul_dbf, DB_CAP_ALL)) { LM_ERR("database module does not implement all functions needed by the module\n"); return -1; } ul_dbf.close(ul_dbh); ul_dbh = 0; return 0; }