예제 #1
0
파일: db.c 프로젝트: cantora/aug-db
static void db_tag_blob(int bid, const char **tags, size_t ntags) {
	int tid;
	size_t i;
	sqlite3_stmt *stmt;
	const char *sql = 
		"INSERT INTO fk_blobs_tags (blob_id, tag_id) "
		"VALUES (?, ?)";

	err_assert(bid > 0);

	if(ntags < 1)
		return;

	DB_STMT_PREP(sql, &stmt);
	DB_BIND_INT(stmt, 1, bid);
	for(i = 0; i < ntags; i++) {
		if(i > 0)
			DB_STMT_RESET(stmt);

		tid = db_find_or_create_tag(tags[i]);
		DB_BIND_INT(stmt, 2, tid);
		if(db_stmt_step(stmt) == 0)
			err_panic(0, "expected SQLITE_DONE from %s: ", sql);
	}

	DB_STMT_FINALIZE(stmt);
}
예제 #2
0
파일: db.c 프로젝트: cantora/aug-db
int db_query_step(struct db_query *query) {
	if(db_stmt_step(query->stmt) != 0) {
		db_query_reset(query);
		return -1;
	}

	return 0;
}
예제 #3
0
파일: db.c 프로젝트: cantora/aug-db
static int db_tag_id(const char *tag) {
	sqlite3_stmt *stmt;
	int id;

	id = 0;
	DB_STMT_PREP("SELECT id FROM tags WHERE name = ?", &stmt);
	DB_BIND_TEXT(stmt, 1, tag);
	if(db_stmt_step(stmt) != 0) 
		goto done; /* no rows in the tags table */

	id = sqlite3_column_int(stmt, 0);
done:
	DB_STMT_FINALIZE(stmt);
	return id;
}
예제 #4
0
파일: db.c 프로젝트: cantora/aug-db
static int db_blob_id(const void *data, size_t bytes) {
	int id;
	sqlite3_stmt *stmt;
	
	id = 0;
	DB_STMT_PREP("SELECT id FROM blobs WHERE value = ?", &stmt);
	DB_BIND_BLOB(stmt, 1, data, bytes);
	if(db_stmt_step(stmt) != 0) 
		goto done; /* no rows in the blobs table */

	id = sqlite3_column_int(stmt, 0);
done:
	DB_STMT_FINALIZE(stmt);
	return id;
}
예제 #5
0
파일: db.c 프로젝트: cantora/aug-db
void db_update_chosen_at(int id) {
	sqlite3_stmt *stmt;

	DB_BEGIN();
	DB_STMT_PREP(
		"UPDATE blobs "
			"SET chosen_at = strftime('%s','now') " 
			"WHERE id = ?", 
		&stmt
	);
	DB_BIND_INT(stmt, 1, id);
	if(db_stmt_step(stmt) != -1)
		err_panic(0, "didnt expect statement to return rows");

	DB_STMT_FINALIZE(stmt);	
	DB_COMMIT();
}
예제 #6
0
파일: db.c 프로젝트: cantora/aug-db
void db_trash(int bid) {
	sqlite3_stmt *stmt;

	DB_BEGIN();
	DB_STMT_PREP(
		"UPDATE blobs "
			"SET trash = 1 "
			"WHERE id = ?", 
		&stmt
	);
	DB_BIND_INT(stmt, 1, bid);
	if(db_stmt_step(stmt) != -1)
		err_panic(0, "didnt expect statement to return rows");

	DB_STMT_FINALIZE(stmt);	
	DB_COMMIT();
}
//default group list
static INT32 _contact_provider_add_default_groups(DatabaseHandle* db_handle)
{


    ContentValues* values=content_values_create();
    INT32  num = 0;
    INT32 i = 0;
    INT32 db_ret=DB_OK;
    DatabaseStatement* stmt = NULL;
    static CHAR* s_contact_group_name[]={"Blacklist","Frequent","Colleague","Classmate","Family","Other"};
    num= sizeof(s_contact_group_name)/sizeof(s_contact_group_name[0]);
    return_val_if_fail(values, DB_ERROR);
    stmt = db_stmt_build_insert_statement(db_handle,CONTACT_ME_GROUP_TABLE_NAME,CONTACT_ME_GROUP_GROUP_COL_NAME,1);
    if (!stmt)
    {
        content_values_destroy(values);
        return DB_ERROR;
    }
    for (i=0;i<num;i++)
    {
        content_values_put_string(values,CONTACT_ME_GROUP_GROUP_COL_NAME,s_contact_group_name[i]);
        db_ret = db_stmt_bind_content_values( stmt,values);
        if (db_ret == DB_OK)
        {
            db_ret=db_stmt_step(stmt);
            if (db_ret!=DB_OK)
            {
                break;
            }
        }

    }
    db_stmt_finalize(stmt);
    content_values_destroy(values);
    return db_ret;

}
static INT32 contact_provider_insert(ContentProvider* thiz,ContentProviderDestination dest,const CHAR* col_list,INT32 col_num, ContentValues* values)
{

    ContactProvider* sub_provider =(ContactProvider*) thiz->priv_data;
    const CHAR* table = NULL;
    ContentValuesItor itor;
    ContentValues *values_me, *values_ext;
    CHAR* values_ret = NULL;
    INT64 ID;
    INT32 db_ret=DB_OK;
    DatabaseStatement* stmt = NULL;
    DatabaseHandle* db_handle = contact_base_provider_obtain_db_handle();
    UINT32 t1 = db_get_ticks();
    UINT32 t2 = 0;
    return_val_if_fail(sub_provider&&db_handle, DB_ERROR);




    switch (dest)
    {
    case CONTACT_PROVIDER_DESTINATION_CONTACTS:
        table = CONTACT_ME_CONTACTS_TABLE_NAME;
        break;
    case CONTACT_PROVIDER_DESTINATION_GROUP:
        table = CONTACT_ME_GROUP_TABLE_NAME;
        break;
    case CONTACT_PROVIDER_DESTINATION_EXTENSION_NUMBER:
        table = CONTACT_EXTENSION_TABLE_NUMBER_NAME;
        break;
    case CONTACT_PROVIDER_DESTINATION_EXTENSION_OTHER:
        table = CONTACT_EXTENSION_TABLE_OTHER_NAME;
        break;
    case CONTACT_PROVIDER_DESTINATION_SIM:
        table = CONTACT_SIM_TABLE_NAME;
        break;
    }
    if (CONTACT_PROVIDER_DESTINATION_CONTACTS==dest)
    {
        INT64 value_group_id,value_main_num_tag;
        WCHAR* str_name=NULL;
        values_me = content_values_create();
        content_values_get_int(values,"group_id",&value_group_id);
        content_values_delete_key(values,"group_id");
        content_values_put_int(values_me,"group_id",value_group_id);
        content_values_get_int(values,"main_num_tag",&value_main_num_tag);
        content_values_delete_key(values,"main_num_tag");
        content_values_put_int(values_me,"main_num_tag",value_main_num_tag);
        content_values_get_string16(values,"name",&str_name);
        content_values_delete_key(values,"name");
        content_values_put_string_16(values_me,"name",str_name);
        db_ret = db_insert(db_handle,table,values_me);
        content_values_destroy(values_me);
        TG_FREE(str_name);
        ID = db_last_insert_rowid(db_handle);
        for (itor=content_values_first(values);itor;itor=content_values_next(values,itor))
        {
            const CHAR* key = content_values_get_key(itor);
            content_values_get_string(values,key,&values_ret);
            values_ext = content_values_create();
            if (0 == strcmp(key,"mobile"))
            {
                content_values_put_int(values_ext,"ID",ID);
                content_values_put_int(values_ext,"tag_id",CONTACT_EXTENSION_TAG_MOBILE);
                content_values_put_string(values_ext,"value",values_ret);
                db_ret |= db_insert(db_handle,CONTACT_EXTENSION_TABLE_NUMBER_NAME,values_ext);
            }
            else if (0 == strcmp(key,"home"))
            {
                content_values_put_int(values_ext,"ID",ID);
                content_values_put_int(values_ext,"tag_id",CONTACT_EXTENSION_TAG_HOME);
                content_values_put_string(values_ext,"value",values_ret);
                db_ret |= db_insert(db_handle,CONTACT_EXTENSION_TABLE_NUMBER_NAME,values_ext);
            }
            else if (0 == strcmp(key,"office"))
            {
                content_values_put_int(values_ext,"ID",ID);
                content_values_put_int(values_ext,"tag_id",CONTACT_EXTENSION_TAG_OFFICE);
                content_values_put_string(values_ext,"value",values_ret);
                db_ret |= db_insert(db_handle,CONTACT_EXTENSION_TABLE_NUMBER_NAME,values_ext);
            }
            else if (0 == strcmp(key,"email"))
            {
                content_values_put_int(values_ext,"ID",ID);
                content_values_put_int(values_ext,"tag_id",CONTACT_EXTENSION_TAG_EMAIL);
                content_values_put_string(values_ext,"value",values_ret);
                db_ret |= db_insert(db_handle,CONTACT_EXTENSION_TABLE_OTHER_NAME,values_ext);
            }
            content_values_destroy(values_ext);
            TG_FREE(values_ret);
        }
        if (DB_OK == db_ret)
        {
            db_ret = (INT32)ID;
        }
        else
        {
            db_ret = -1;
        }
    }
    else
    {
        stmt = db_stmt_build_insert_statement(db_handle,table,col_list,col_num);
        return_val_if_fail(stmt, DB_ERROR);
        db_ret= db_stmt_bind_content_values( stmt,(ContentValues*)values);
        if (db_ret==DB_OK)
            db_ret=db_stmt_step(stmt);
        db_stmt_finalize(stmt);
    }
    contact_base_provider_release_db_handle();

    t2 = db_get_ticks();
    DB_PRINTF("contact_provider_insert use %d\n",t2-t1);


    return db_ret;

}