@@ -2159,7 +2159,7 @@ int cloudsync_payload_apply (sqlite3_context *context, const char *payload, int
21592159 if (rc != SQLITE_DONE ) {
21602160 // don't "break;", the error can be due to a RLS policy.
21612161 // in case of error we try to apply the following changes
2162- printf ("cloudsync_payload_apply error in step : (%d) %s\n" , rc , sqlite3_errmsg (db ));
2162+ printf ("cloudsync_payload_apply error on db_version %lld/%lld : (%d) %s\n" , decoded_context . db_version , decoded_context . seq , rc , sqlite3_errmsg (db ));
21632163 }
21642164 }
21652165
@@ -2170,6 +2170,9 @@ int cloudsync_payload_apply (sqlite3_context *context, const char *payload, int
21702170 stmt_reset (vm );
21712171 }
21722172
2173+ char * lasterr = NULL ;
2174+ if (rc != SQLITE_OK && rc != SQLITE_DONE ) lasterr = cloudsync_string_dup (sqlite3_errmsg (db ), false);
2175+
21732176 if (payload_apply_callback ) payload_apply_callback (& payload_apply_xdata , & decoded_context , db , data , CLOUDSYNC_PAYLOAD_APPLY_CLEANUP , rc );
21742177
21752178 if (rc == SQLITE_DONE ) rc = SQLITE_OK ;
@@ -2193,8 +2196,9 @@ int cloudsync_payload_apply (sqlite3_context *context, const char *payload, int
21932196 if (clone ) cloudsync_memory_free (clone );
21942197
21952198 if (rc != SQLITE_OK ) {
2196- sqlite3_result_error (context , sqlite3_errmsg ( db ) , -1 );
2199+ sqlite3_result_error (context , lasterr , -1 );
21972200 sqlite3_result_error_code (context , SQLITE_MISUSE );
2201+ cloudsync_memory_free (lasterr );
21982202 return -1 ;
21992203 }
22002204
0 commit comments