Skip to content

Commit 54d7df1

Browse files
committed
database_value_text returns NULL also in PostgreSQL implementation
1 parent 65c716a commit 54d7df1

4 files changed

Lines changed: 15 additions & 3 deletions

File tree

src/cloudsync.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -860,8 +860,10 @@ int table_add_stmts (cloudsync_table_context *table, int ncols) {
860860
cloudsync_table_context *table_lookup (cloudsync_context *data, const char *table_name) {
861861
DEBUG_DBFUNCTION("table_lookup %s", table_name);
862862

863-
for (int i=0; i<data->tables_count; ++i) {
864-
if ((strcasecmp(data->tables[i]->name, table_name) == 0)) return data->tables[i];
863+
if (table_name) {
864+
for (int i=0; i<data->tables_count; ++i) {
865+
if ((strcasecmp(data->tables[i]->name, table_name) == 0)) return data->tables[i];
866+
}
865867
}
866868

867869
return NULL;

src/dbutils.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,18 @@ int dbutils_value_compare (dbvalue_t *lvalue, dbvalue_t *rvalue) {
5454
case DBTYPE_TEXT: {
5555
const char *l_text = database_value_text(lvalue);
5656
const char *r_text = database_value_text(rvalue);
57+
if (l_text == NULL && r_text == NULL) return 0;
58+
if (l_text == NULL && r_text != NULL) return -1;
59+
if (l_text != NULL && r_text == NULL) return 1;
5760
return strcmp((const char *)l_text, (const char *)r_text);
5861
} break;
5962

6063
case DBTYPE_BLOB: {
6164
const void *l_blob = database_value_blob(lvalue);
6265
const void *r_blob = database_value_blob(rvalue);
66+
if (l_blob == NULL && r_blob == NULL) return 0;
67+
if (l_blob == NULL && r_blob != NULL) return -1;
68+
if (l_blob != NULL && r_blob == NULL) return 1;
6369
int l_size = database_value_bytes(lvalue);
6470
int r_size = database_value_bytes(rvalue);
6571
int cmp = memcmp(l_blob, r_blob, (l_size < r_size) ? l_size : r_size);

src/postgresql/database_postgresql.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2203,7 +2203,7 @@ int64_t database_value_int (dbvalue_t *value) {
22032203

22042204
const char *database_value_text (dbvalue_t *value) {
22052205
pgvalue_t *v = (pgvalue_t *)value;
2206-
if (!v || v->isnull) return "";
2206+
if (!v || v->isnull) return NULL;
22072207

22082208
if (!v->cstring) {
22092209
PG_TRY();

src/sqlite/cloudsync_sqlite.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ void dbsync_col_value (sqlite3_context *context, int argc, sqlite3_value **argv)
199199

200200
// retrieve column name
201201
const char *col_name = (const char *)database_value_text(argv[1]);
202+
if (!col_name) {
203+
dbsync_set_error(context, "Column name cannot be NULL");
204+
return;
205+
}
202206

203207
// check for special tombstone value
204208
if (strcmp(col_name, CLOUDSYNC_TOMBSTONE_VALUE) == 0) {

0 commit comments

Comments
 (0)