@@ -214,6 +214,7 @@ bool force_uncompressed_blob = false;
214214
215215// Internal prototypes
216216int local_mark_insert_or_update_meta (cloudsync_table_context * table , const char * pk , size_t pklen , const char * col_name , int64_t db_version , int seq );
217+ int cloudsync_set_error (cloudsync_context * data , const char * err_user , int err_code );
217218int cloudsync_set_dberror (cloudsync_context * data );
218219
219220// MARK: - CRDT algos -
@@ -439,7 +440,7 @@ int cloudsync_load_siteid (db_t *db, cloudsync_context *data) {
439440 if (rc != DBRES_OK ) return rc ;
440441 if (!buffer || size != UUID_LEN ) {
441442 if (buffer ) cloudsync_memory_free (buffer );
442- return DBRES_MISUSE ;
443+ return cloudsync_set_error ( data , "Unable to retrieve siteid" , DBRES_MISUSE ) ;
443444 }
444445
445446 memcpy (data -> site_id , buffer , UUID_LEN );
@@ -473,14 +474,14 @@ int cloudsync_add_dbvms (db_t *db, cloudsync_context *data) {
473474 int rc = database_prepare (db , SQL_DATA_VERSION , (void * * )& data -> data_version_stmt , DBFLAG_PERSISTENT );
474475 DEBUG_STMT ("data_version_stmt %p" , data -> data_version_stmt );
475476 if (rc != DBRES_OK ) return rc ;
476- DEBUG_SQL ("data_version_stmt: %s" , sql );
477+ DEBUG_SQL ("data_version_stmt: %s" , SQL_DATA_VERSION );
477478 }
478479
479480 if (data -> schema_version_stmt == NULL ) {
480481 int rc = database_prepare (db , SQL_SCHEMA_VERSION , (void * * )& data -> schema_version_stmt , DBFLAG_PERSISTENT );
481482 DEBUG_STMT ("schema_version_stmt %p" , data -> schema_version_stmt );
482483 if (rc != DBRES_OK ) return rc ;
483- DEBUG_SQL ("schema_version_stmt: %s" , sql );
484+ DEBUG_SQL ("schema_version_stmt: %s" , SQL_SCHEMA_VERSION );
484485 }
485486
486487 if (data -> getset_siteid_stmt == NULL ) {
@@ -490,7 +491,7 @@ int cloudsync_add_dbvms (db_t *db, cloudsync_context *data) {
490491 int rc = database_prepare (db , SQL_SITEID_GETSET_ROWID_BY_SITEID , (void * * )& data -> getset_siteid_stmt , DBFLAG_PERSISTENT );
491492 DEBUG_STMT ("getset_siteid_stmt %p" , data -> getset_siteid_stmt );
492493 if (rc != DBRES_OK ) return rc ;
493- DEBUG_SQL ("getset_siteid_stmt: %s" , sql );
494+ DEBUG_SQL ("getset_siteid_stmt: %s" , SQL_SITEID_GETSET_ROWID_BY_SITEID );
494495 }
495496
496497 return cloudsync_dbversion_rebuild (db , data );
@@ -582,9 +583,9 @@ char *table_build_values_sql (db_t *db, cloudsync_table_context *table) {
582583 goto process_process ;
583584 }
584585 #endif
585-
586+
586587 sql = cloudsync_memory_mprintf (SQL_BUILD_SELECT_NONPK_COLS_BY_PK , table -> name , table -> name , singlequote_escaped_table_name );
587-
588+
588589#if !CLOUDSYNC_DISABLE_ROWIDONLY_TABLES
589590process_process :
590591#endif
@@ -865,7 +866,8 @@ int table_add_stmts (db_t *db, cloudsync_table_context *table, int ncols) {
865866 if (rc != DBRES_OK ) goto cleanup ;
866867
867868 // REAL TABLE statements
868-
869+ DEBUG_SQL ("REAL TABLE statements: %d" , ncols );
870+
869871 // precompile the get column value statement
870872 if (ncols > 0 ) {
871873 sql = table_build_values_sql (db , table );
@@ -877,6 +879,7 @@ int table_add_stmts (db_t *db, cloudsync_table_context *table, int ncols) {
877879 if (rc != DBRES_OK ) goto cleanup ;
878880 }
879881
882+ DEBUG_SQL ("real_merge_delete ..." , sql );
880883 sql = table_build_mergedelete_sql (db , table );
881884 if (!sql ) {rc = DBRES_NOMEM ; goto cleanup ;}
882885 DEBUG_SQL ("real_merge_delete: %s" , sql );
@@ -894,7 +897,7 @@ int table_add_stmts (db_t *db, cloudsync_table_context *table, int ncols) {
894897 if (rc != DBRES_OK ) goto cleanup ;
895898
896899cleanup :
897- if (rc != DBRES_OK ) printf ("table_add_stmts error: %s\n" , database_errmsg (db ));
900+ if (rc != DBRES_OK ) DEBUG_ALWAYS ("table_add_stmts error: %d % s\n" , rc , database_errmsg (db ));
898901 return rc ;
899902}
900903
@@ -1610,7 +1613,7 @@ int cloudsync_begin_alter (cloudsync_context *data, const char *table_name) {
16101613
16111614 // init cloudsync_settings
16121615 if (cloudsync_context_init (data , db ) == NULL ) {
1613- return cloudsync_set_error ( data , "Unable to initialize cloudsync context" , DBRES_MISUSE ) ;
1616+ return DBRES_MISUSE ;
16141617 }
16151618
16161619 // lookup table
@@ -2622,8 +2625,7 @@ int cloudsync_init_table (cloudsync_context *data, const char *table_name, const
26222625
26232626 // init cloudsync_settings
26242627 if (cloudsync_context_init (data , db ) == NULL ) {
2625- // TODO: check error message here
2626- return DBRES_MISUSE ;
2628+ return cloudsync_set_error (data , "Unable to initialize cloudsync context" , DBRES_MISUSE );
26272629 }
26282630
26292631 // sanity check algo name (if exists)
0 commit comments