/* * Loads the Customer Table */ void LoadCust(void) { long w_id; long d_id; char *name = CUSTOMER_INDEX_NAME; char *sec_name = CUSTOMER_SECONDARY_NAME; char *hist_name = HISTORY_INDEX_NAME; DB *dbp_sec; int err; if(create_db(db_env, &dbp_customer,DB_COMMON_PAGE_SIZE, 0) || open_db(dbp_customer, name, 0)) return; if(create_db(db_env, &dbp_sec, DB_COMMON_PAGE_SIZE, DB_DUP | DB_DUPSORT)) return; if((err = dbp_sec->set_bt_compare(dbp_sec, customer_secondary_comparison_func))) { db_error("DB->set_bt_compare", err); goto done; } if(open_db(dbp_sec, sec_name, 0)) return; if ((err = dbp_customer->associate(dbp_customer, 0, dbp_sec, get_customer_sec_key, 0)) != 0) { db_error("DB->associate failed: %s\n", err); goto done; } if(create_db(db_env, &dbp_history, DB_COMMON_PAGE_SIZE, 0) || open_db(dbp_history, hist_name, 0)) return; for (w_id=1L; w_id<=count_ware; w_id++) for (d_id=1L; d_id<=DIST_PER_WARE; d_id++) { if(Customer(d_id,w_id)) goto done; } done: if(dbp_customer) dbp_customer->close(dbp_customer, 0); if(dbp_sec) dbp_sec->close(dbp_sec, 0); if(dbp_history) dbp_history->close(dbp_history, 0); }
/* * student login record init * * We can use a file to store login record and * use a sql database * */ int login_record_init(void) { // Set up a file student_file = fopen(STUDENT_LOGIN_RECORD,"w"); if (!student_file) { fprintf(stderr,"Error creating a login record file\n"); exit(-1); } fprintf(stderr, "Student login records created %s\n", STUDENT_LOGIN_RECORD); // Set up a table in the database if (open_db(&db, DB_NAME) < 0 ) { fprintf(stderr, "open_db failed!\n"); return -1; } fprintf(stderr, "Student login database created %s\n", DB_NAME); // Create a table for student records char sql_statement[256]; sprintf(sql_statement, "CREATE TABLE IF NOT EXISTS " TABLE_NAME "(ID CHAR(10) PRIMARY KEY NOT NULL,TIME CHAR(128));"); if (exec_sql_db(db, sql_statement) < 0 ) { fprintf(stderr,"failed to create table\n"); return -1; } fprintf(stderr, "Student login table created %s\n", TABLE_NAME); return; }
int ccnet_user_manager_prepare (CcnetUserManager *manager) { int ret; #ifdef HAVE_LDAP if (try_load_ldap_settings (manager) < 0) return -1; #endif int iter = g_key_file_get_integer (manager->session->keyf, "USER", "PASSWORD_HASH_ITERATIONS", NULL); if (iter <= 0) iter = DEFAULT_PASSWD_HASH_ITER; manager->passwd_hash_iter = iter; manager->userdb_path = g_build_filename (manager->session->config_dir, "user-db", NULL); ret = open_db(manager); if (ret < 0) return ret; manager->priv->cur_users = ccnet_user_manager_count_emailusers (manager); if (manager->priv->max_users != 0 && manager->priv->cur_users > manager->priv->max_users) { ccnet_warning ("The number of users exceeds limit, max %d, current %d\n", manager->priv->max_users, manager->priv->cur_users); return -1; } return 0; }
/*********************************************************************** * * Function: sync_CopyToPilot * * Summary: Copy all desktop records to the Palm * * Parameters: None * * Returns: 0 on success, non-zero otherwise * ***********************************************************************/ int sync_CopyToPilot(SyncHandler * sh) { int dbhandle, slow = 0, result = 0; DesktopRecord *drecord = NULL; result = open_db(sh, &dbhandle); if (result < 0) goto cleanup; result = sh->Pre(sh, dbhandle, &slow); if (result < 0) goto cleanup; result = dlp_DeleteRecord(sh->sd, dbhandle, 1, 0); if (result < 0) goto cleanup; while (sh->ForEach(sh, &drecord) == 0 && drecord) { result = store_record_on_pilot(sh, dbhandle, drecord, BOTH); if (result < 0) goto cleanup; } result = sh->Post(sh, dbhandle); cleanup: close_db(sh, dbhandle); return result; }
int update_myProfile(const char *id,const char *name,const char *sex,const char *age,const char *introduction,const char *head_image_path, const char *v4_port, const char *v6_port) { char *errmsg=0;//记录返回的错误信息。 sqlite3 *db=0; //记录返回的数据库句柄 if(!open_db(&db, MYINFO_DBFILE_NAME)) return false; int iid = atoi(id); char *szSql = NULL; //下述函数进行数据库添加操作 if(iid == 0) { char *szBaseSql = "insert into my_profile(nick_name,sex,age,introduction,head_image_path,v4_port,v6_port) values('"; szSql = v6strcat(15, szBaseSql, name, "','", sex, "','", age, "','",introduction,"','",head_image_path,"','",v4_port,"','",v6_port,"')"); } else { char *szBaseSql = "insert or replace into my_profile(id,nick_name,sex,age,introduction,head_image_path,v4_port,v6_port) values('"; szSql = v6strcat(17, szBaseSql, id, "','", name, "','", sex, "','", age, "','",introduction,"','",head_image_path,"','",v4_port,"','",v6_port,"')"); } int rc=sqlite3_exec(db,szSql,0,0,&errmsg); release_db_data((void **)&szSql); CHECK_RC(rc,errmsg,db); //下述函数获取数据库插入的数据的ID if(iid == 0) iid = (int) sqlite3_last_insert_rowid(db); sqlite3_close(db); return iid; }
int ccnet_user_manager_prepare (CcnetUserManager *manager) { int ret; #ifdef HAVE_LDAP if (try_load_ldap_settings (manager) < 0) return -1; #endif manager->userdb_path = g_build_filename (manager->session->config_dir, "user-db", NULL); ret = open_db(manager); if (ret < 0) return ret; manager->priv->cur_users = ccnet_user_manager_count_emailusers (manager); if (manager->priv->max_users != 0 && manager->priv->cur_users > manager->priv->max_users) { ccnet_warning ("The number of users exceeds limit, max %d, current %d\n", manager->priv->max_users, manager->priv->cur_users); return -1; } return 0; }
bool get_chatItems(const char *uid, const char *id, const char *num, char ***chat_table, int *rows, int *cols) { char *errmsg=0;//记录返回的错误信息。 sqlite3 *db=0; //记录返回的数据库句柄 if(!open_db(&db, CHATHISTORY_DBFILE_NAME)) return false; //下述函数进行查询数据库操作 char *szBaseSql = "select * from chat_with_"; char *szSql = NULL; int iid = atoi(id); if(iid > -1) { szSql = v6strcat(6, szBaseSql, uid, " limit ", id, ",", num); } else { szSql = v6strcat(4, szBaseSql, uid, " order by id desc limit ", num); } int rc=sqlite3_get_table(db,szSql,chat_table,rows,cols,&errmsg); CHECK_RC(rc,errmsg,db); bool success = true; if(SQLITE_OK != errmsg) success = false; sqlite3_close(db); return success; }
int main(int argc, char **argv) { GapIO *io; char *project, *version; int status; int argn; if (argc < 2) { usage(); } for (argn = 1; argn < argc; argn++) { project = argv[argn]; version = strchr(project, '.'); if (!version) { fprintf(stderr, "Malformed project name\n"); return 1; } *version++ = 0; printf("Opening project '%s' version '%s'\n", project, version); io = open_db(project, version, &status, 0, 1); if (!io) { fprintf(stderr, "Couldn't open database\n"); return 1; } read_size_dist(io); close_db(io); } return 0; }
/**************** * Flush the cache. This cannot be used while in a transaction. */ int tdbio_sync() { CACHE_CTRL r; int did_lock = 0; if( db_fd == -1 ) open_db(); if( in_transaction ) log_bug("tdbio: syncing while in transaction\n"); if( !cache_is_dirty ) return 0; if (!take_write_lock ()) did_lock = 1; for( r = cache_list; r; r = r->next ) { if( r->flags.used && r->flags.dirty ) { int rc = write_cache_item( r ); if( rc ) return rc; } } cache_is_dirty = 0; if (did_lock) release_write_lock (); return 0; }
/* * Cursor sqliteU61Query(String filename, String sql, String[] values) * * Query an SQLite database and return the results in a Cursor. */ JNIEXPORT jobject JNICALL Java_eu_gounot_bnfdata_provider_SuggestionsProvider_sqliteU61Query (JNIEnv *env, jobject j_this, jstring j_filename, jstring j_sql, jobjectArray j_values) { sqlite3 *db; sqlite3_stmt *stmt = NULL; jobjectArray j_col_array; jobject j_cursor = NULL; if ((db = open_db(env, j_filename)) == NULL) goto finish; if ((stmt = prepare_stmt(env, db, j_sql)) == NULL) goto finish; if ((j_col_array = create_col_array(env, stmt)) == NULL) goto finish; if (!bind_stmt_values(env, stmt, j_values)) goto finish; j_cursor = exec_query(env, stmt, j_col_array); finish: sqlite3_finalize(stmt); sqlite3_close(db); return j_cursor; }
int getpwnam_r(const char *name, struct passwd *pwd, char *buf, size_t buflen, struct passwd **result) { int res; FILE *file; if (0 != (res = open_db(PASSWD_FILE, &file))) { *result = NULL; return res; } while (0 == (res = fgetpwent_r(file, pwd, buf, buflen, result))) { if (0 == strcmp(pwd->pw_name, name)) { break; } } fclose(file); if (0 != res) { result = NULL; return res == ENOENT ? 0 : -1; } return 0; }
int getpwuid_r(uid_t uid, struct passwd *pwd, char *buf, size_t buflen, struct passwd **result) { int res; FILE *file; if (0 != (res = open_db(PASSWD_FILE, &file))) { *result = NULL; return res; } while (0 == (res = fgetpwent_r(file, pwd, buf, buflen, result))) { if (pwd->pw_uid == uid) { break; } } fclose(file); if (0 != res) { result = NULL; return res == ENOENT ? 0 : -1; } return 0; }
int last_insert_peerProfileUid() { char *errmsg=0;//记录返回的错误信息。 sqlite3 *db=0; //记录返回的数据库句柄 if(!open_db(&db, PEERSINFO_DBFILE_NAME)) return 0; // 下述函数获取数据库最后一条数据的ID sqlite3_stmt *stmt; char *szBaseSql = "select seq from sqlite_sequence where name='peers_profile'"; sqlite3_prepare(db, szBaseSql, -1,&stmt,0); int rc = sqlite3_step(stmt); sqlite3_int64 lid = 0; if(rc == SQLITE_ROW) { lid = sqlite3_column_int64(stmt,0); } sqlite3_finalize(stmt); sqlite3_close(db); return lid; }
int main (int argc, char **argv) { BASE_DIR = argv[1]; LOG_DIR = argv[2]; VERBOSITY = atoi(argv[3]); char *command = argv[4]; char *param = argv[5]; // Setup char *db = o_printf("%s/openDIAS.sqlite3", BASE_DIR); o_log(DEBUGM,"database file is %s",db); if(open_db (db)) { o_log(ERROR, "Could not connect to the database."); free(db); exit(EXIT_FAILURE); } free(db); locale_init( "en" ); // Let's do the work o_log( INFORMATION, "Worker started and ready to process: %s", command); sane_worker( command, param ); // Finish up now close_all(); exit(EXIT_SUCCESS); }
/*********************************************************************** * * Function: sync_MergeToPilot * * Summary: Synchronize the desktop records to the pilot, but do * not alter the desktop records * * Parameters: None * * Returns: 0 on success, non-zero otherwise * ***********************************************************************/ int sync_MergeToPilot(SyncHandler * sh) { int dbhandle, slow = 0, result = 0; result = open_db(sh, &dbhandle); if (result < 0) goto cleanup; result = sh->Pre(sh, dbhandle, &slow); if (result < 0) goto cleanup; if (!slow) { sync_MergeToPilot_fast(sh, dbhandle, PILOT); if (result < 0) goto cleanup; } else { sync_MergeToPilot_slow(sh, dbhandle, PILOT); if (result < 0) goto cleanup; } result = sh->Post(sh, dbhandle); cleanup: close_db(sh, dbhandle); return result; }
int update_serverInformation(const char *sid, const char *name, const char *ip, const char *port, const char *description, const char *uid, const char *upassword) { char *errmsg=0;//记录返回的错误信息。 sqlite3 *db=0; //记录返回的数据库句柄 if(!open_db(&db, SERVERSINFO_DBFILE_NAME)) return false; //下述函数进行数据库添加操作 int id = atoi(sid); char *szSql = NULL; if(id == 0) { char *szBaseSql = "insert into server_information(name,ip,port,description,uid,upassword) values('"; char *szSql = v6strcat(13, szBaseSql, name, "','", ip, "','", port, "','",description, "','",uid, "','",upassword,"')"); } else { char *szBaseSql = "insert or replace into server_information(id,name,ip,port,description,uid,upassword) values('"; szSql = v6strcat(15, szBaseSql, sid, "','", name, "','", ip, "','", port, "','",description, "','",uid, "','",upassword,"')"); } int rc=sqlite3_exec(db,szSql,0,0,&errmsg); release_db_data((void **)&szSql); CHECK_RC(rc,errmsg,db); //下述函数获取数据库插入的数据的ID if(id == 0) id = (int) sqlite3_last_insert_rowid(db); sqlite3_close(db); return id; }
void test_db(int n) { char *dir = Option.dir; struct db db; u64 key; struct lump val; u64 i; int rc; if (1) set_cleanup(cleanup); create_db(dir); db = open_db(dir); for (i = 0; i < n; i++) { key = randkey(); if (0) val = randlump(); if (1) val = key2lump(key); //printf("%lld %*s %zd\n", key, val.size, (char *)val.d, strlen(val.d)); insert_db(&db, key, val); } if (1) for (i = 0; i < n + 1; i++) { rc = next_log(db.r); if (rc == DONE) break; //printf("%lld %s\n", key_log(db.r), (char *)val_log(db.r).d); } if (1) merge_db(&db); close_db(&db); destroy_db(dir); }
bool insert_peersProfile(const insert_peer_profile_list peers_list) { char *errmsg=0;//记录返回的错误信息。 sqlite3 *db=0; //记录返回的数据库句柄 if(!open_db(&db, PEERSINFO_DBFILE_NAME)) return false; int rc = sqlite3_exec(db, "begin transaction", 0, 0, &errmsg); // 开启事务处理 CHECK_RC(rc,errmsg,db); const new_peer_profile* p = peers_list->next; while(p) { char *szBaseSql = "insert into peers_profile(nick_name,group_name,sex,age,introduction,head_image_path,server_id,server_uid,last_ip,last_tcp_port,last_udp_port) values('"; char *szSql = v6strcat(23, szBaseSql, p->nick_name, "','", p->group_name, "','", p->sex, "','",p->age, "','",p->introduction, "','",p->head_image_path, "','",p->server_id, "','",p->server_uid, "','",p->last_ip, "','",p->tcp_port, "','",p->udp_port,"')"); int rc=sqlite3_exec(db,szSql,0,0,&errmsg); release_db_data((void **)&szSql); if(rc!=SQLITE_OK) { sqlite3_free(errmsg); } p = p->next; } rc = sqlite3_exec(db, "commit transaction", 0, 0, &errmsg); // 提交事务 CHECK_RC(rc,errmsg,db); sqlite3_close(db); return true; }
int main(int argc, char* argv[]) { if (argc < 3) { usage(); return 1; } const char* db = argv[2]; Lux::Config::Document config; if (!Lux::DocumentConfigParser::parse(db, config)) { std::cerr << "parse failed - " << db << std::endl; return 1; } Lux::Engine engine(config); const char* cmd = argv[1]; if (strcmp(cmd, "init") == 0) { return init(engine, db, argc - 3, argv + 3); } if (!open_db(engine, db)) { return 1; } if (strcmp(cmd, "put") == 0) { return put(engine, argc - 3, argv + 3); } if (strcmp(cmd, "search") == 0) { return search(engine, argc - 3, argv + 3); } return 0; }
static krb5_error_code ctx_lock(krb5_context context, krb5_db2_context *dbc, int lockmode) { krb5_error_code retval; int kmode, tries; if (lockmode == KRB5_DB_LOCKMODE_PERMANENT || lockmode == KRB5_DB_LOCKMODE_EXCLUSIVE) kmode = KRB5_LOCKMODE_EXCLUSIVE; else if (lockmode == KRB5_DB_LOCKMODE_SHARED) kmode = KRB5_LOCKMODE_SHARED; else return EINVAL; if (dbc->db_locks_held == 0 || dbc->db_lock_mode < kmode) { /* Acquire or upgrade the lock. */ for (tries = 0; tries < MAX_LOCK_TRIES; tries++) { retval = krb5_lock_file(context, dbc->db_lf_file, kmode | KRB5_LOCKMODE_DONTBLOCK); if (retval == 0) break; if (retval == EBADF && kmode == KRB5_LOCKMODE_EXCLUSIVE) /* Tried to lock something we don't have write access to. */ return KRB5_KDB_CANTLOCK_DB; sleep(1); } if (retval == EACCES) return KRB5_KDB_CANTLOCK_DB; else if (retval == EAGAIN || retval == EWOULDBLOCK) return OSA_ADB_CANTLOCK_DB; else if (retval) return retval; /* Open the DB (or re-open it for read/write). */ if (dbc->db != NULL) dbc->db->close(dbc->db); dbc->db = open_db(dbc, kmode == KRB5_LOCKMODE_SHARED ? O_RDONLY : O_RDWR, 0600); if (dbc->db == NULL) { retval = errno; dbc->db_locks_held = 0; dbc->db_lock_mode = 0; (void) osa_adb_release_lock(dbc->policy_db); (void) krb5_lock_file(context, dbc->db_lf_file, KRB5_LOCKMODE_UNLOCK); return retval; } dbc->db_lock_mode = kmode; } dbc->db_locks_held++; /* Acquire or upgrade the policy lock. */ retval = osa_adb_get_lock(dbc->policy_db, lockmode); if (retval) (void) ctx_unlock(context, dbc); return retval; }
int main(int argc, char** argv) { open_db(); create_tab(); insert_db(); select_db(); close_db(); }
int main(int argc, char* argv[]) { open_db(); server(); close_db(); return 0; }
G_MODULE_EXPORT void db_chooser_dialog_file_activated_cb(GtkFileChooser* chooser, gpointer user_data) { char* path = gtk_file_chooser_get_filename(chooser); SSE_APP* app = (SSE_APP*)user_data; if(open_db(app, path) == EXIT_SUCCESS) gtk_widget_hide(GTK_WIDGET(chooser)); g_free(path); }
static krb5_error_code ctx_lock(krb5_context context, krb5_db2_context *dbc, int lockmode) { krb5_error_code retval; int kmode; if (lockmode == KRB5_DB_LOCKMODE_PERMANENT || lockmode == KRB5_DB_LOCKMODE_EXCLUSIVE) kmode = KRB5_LOCKMODE_EXCLUSIVE; else if (lockmode == KRB5_DB_LOCKMODE_SHARED) kmode = KRB5_LOCKMODE_SHARED; else return EINVAL; if (dbc->db_locks_held == 0 || dbc->db_lock_mode < kmode) { /* Acquire or upgrade the lock. */ retval = krb5_lock_file(context, dbc->db_lf_file, kmode); /* Check if we tried to lock something not open for write. */ if (retval == EBADF && kmode == KRB5_LOCKMODE_EXCLUSIVE) return KRB5_KDB_CANTLOCK_DB; else if (retval == EACCES || retval == EAGAIN || retval == EWOULDBLOCK) return KRB5_KDB_CANTLOCK_DB; else if (retval) return retval; /* Open the DB (or re-open it for read/write). */ if (dbc->db != NULL) dbc->db->close(dbc->db); dbc->db = open_db(dbc, kmode == KRB5_LOCKMODE_SHARED ? O_RDONLY : O_RDWR, 0600); if (dbc->db == NULL) { retval = errno; dbc->db_locks_held = 0; dbc->db_lock_mode = 0; (void) osa_adb_release_lock(dbc->policy_db); (void) krb5_lock_file(context, dbc->db_lf_file, KRB5_LOCKMODE_UNLOCK); return retval; } dbc->db_lock_mode = kmode; } dbc->db_locks_held++; /* Acquire or upgrade the policy lock. */ retval = osa_adb_get_lock(dbc->policy_db, lockmode); if (retval) { (void) ctx_unlock(context, dbc); if (retval == OSA_ADB_NOEXCL_PERM || retval == OSA_ADB_CANTLOCK_DB || retval == OSA_ADB_NOLOCKFILE) retval = KRB5_KDB_CANTLOCK_DB; } return retval; }
int seaf_branch_manager_init (SeafBranchManager *mgr) { #if defined( SEAFILE_SERVER ) && defined( FULL_FEATURE ) mgr->priv->cevent_id = cevent_manager_register (seaf->ev_mgr, (cevent_handler)publish_repo_update_event, NULL); #endif return open_db (mgr); }
int ccnet_user_manager_prepare (CcnetUserManager *manager) { #ifdef HAVE_LDAP if (try_load_ldap_settings (manager) < 0) return -1; #endif manager->userdb_path = g_build_filename (manager->session->config_dir, "user-db", NULL); return open_db(manager); }
void db_reconnect(int fd, short what, void *ctx) { int i, s; s = db_status; if (s != TTESUCCESS && s != TTEINVALID && s != TTEKEEP && s != TTENOREC) { db_status = open_db(db_host, db_port, &rdb); } evtimer_del(&ev); evtimer_set(&ev, db_reconnect, NULL); evtimer_add(&ev, &tv); }
int main(int argc, const char **argv) { usage(argc); get_db_path(argc, argv); get_name(argc, argv); open_db(); create_table(); generate_keypair(); insert_keypair(); close_db(); return 0; }
int main(int argc, char **argv) { GapIO *io; char *project, *version; int status; int argn; int chemistry; int total_conf[MAXREADLEN]; double total_dconf[MAXREADLEN]; int count = 0; int i; if (argc < 3) { usage(); } chemistry = atoi(argv[1]); memset(total_conf, 0, MAXREADLEN * sizeof(int)); for (argn = 2; argn < argc; argn++) { project = argv[argn]; version = strchr(project, '.'); if (!version) { fprintf(stderr, "Malformed project name\n"); return 1; } *version++ = 0; fprintf(stderr, "Opening project '%s' version '%s'\n", project, version); io = open_db(project, version, &status, 0, 1); if (!io) { fprintf(stderr, "Couldn't open database\n"); return 1; } count += read_conf_dist(io, chemistry, total_conf); close_db(io); } fprintf(stderr, "Count = %d\n", count); for (i = 0; i < MAXREADLEN; i++) { total_dconf[i] = total_conf[i] / (double)count; } for (i = 0; i < MAXREADLEN; i++) { printf("%4d %f\n", i, total_dconf[i]); } return 0; }
/* Return successfully if the db2 name set in context can be opened. */ static krb5_error_code check_openable(krb5_context context) { DB *db; krb5_db2_context *dbc; dbc = context->dal_handle->db_context; db = open_db(dbc, O_RDONLY, 0); if (db == NULL) return errno; db->close(db); return 0; }