@@ -442,13 +442,9 @@ bool database_system_exists (cloudsync_context *data, const char *name, const ch
442442 bool exists = false;
443443
444444 if (strcmp (type , "table" ) == 0 ) {
445- snprintf (query , sizeof (query ),
446- "SELECT 1 FROM pg_tables WHERE schemaname = 'public' AND tablename = '%s'" ,
447- name );
445+ snprintf (query , sizeof (query ), "SELECT 1 FROM pg_tables WHERE schemaname = 'public' AND tablename = '%s'" , name );
448446 } else if (strcmp (type , "trigger" ) == 0 ) {
449- snprintf (query , sizeof (query ),
450- "SELECT 1 FROM pg_trigger WHERE tgname = '%s'" ,
451- name );
447+ snprintf (query , sizeof (query ), "SELECT 1 FROM pg_trigger WHERE tgname = '%s'" , name );
452448 } else {
453449 return false;
454450 }
@@ -951,7 +947,9 @@ int database_pk_names (cloudsync_context *data, const char *table_name, char ***
951947 Datum datum = SPI_getbinval (tuple , SPI_tuptable -> tupdesc , 1 , & isnull );
952948 if (!isnull ) {
953949 text * txt = DatumGetTextP (datum );
950+ MemoryContext old = MemoryContextSwitchTo (TopMemoryContext );
954951 pk_names [i ] = text_to_cstring (txt );
952+ MemoryContextSwitchTo (old );
955953 } else {
956954 pk_names [i ] = NULL ;
957955 }
@@ -1306,20 +1304,21 @@ int databasevm_bind_value (dbvm_t *vm, int index, dbvalue_t *value) {
13061304
13071305 pg_stmt_t * stmt = (pg_stmt_t * )vm ;
13081306 pgvalue_t * v = (pgvalue_t * )value ;
1309- if (!v ) {
1307+ if (!v || v -> isnull ) {
13101308 stmt -> values [idx ] = (Datum )0 ;
13111309 stmt -> types [idx ] = TEXTOID ;
13121310 stmt -> nulls [idx ] = 'n' ;
13131311 } else {
13141312 int16 typlen ;
13151313 bool typbyval ;
1316- MemoryContext old = MemoryContextSwitchTo ( stmt -> bind_mcxt );
1314+
13171315 get_typlenbyval (v -> typeid , & typlen , & typbyval );
1316+ MemoryContext old = MemoryContextSwitchTo (stmt -> bind_mcxt );
13181317 Datum dcopy = typbyval ? v -> datum : datumCopy (v -> datum , typbyval , typlen );
1319- stmt -> values [idx ] = v -> isnull ? ( Datum ) 0 : dcopy ;
1318+ stmt -> values [idx ] = dcopy ;
13201319 MemoryContextSwitchTo (old );
13211320 stmt -> types [idx ] = OidIsValid (v -> typeid ) ? v -> typeid : TEXTOID ;
1322- stmt -> nulls [idx ] = v -> isnull ? 'n' : ' ' ;
1321+ stmt -> nulls [idx ] = ' ' ;
13231322 }
13241323
13251324 if (stmt -> nparams < idx + 1 ) stmt -> nparams = idx + 1 ;
@@ -1715,11 +1714,7 @@ void *dbmem_alloc (uint64_t size) {
17151714}
17161715
17171716void * dbmem_zeroalloc (uint64_t size ) {
1718- void * ptr = palloc (size );
1719- if (ptr ) {
1720- memset (ptr , 0 , (size_t )size );
1721- }
1722- return ptr ;
1717+ return palloc0 (size );
17231718}
17241719
17251720void * dbmem_realloc (void * ptr , uint64_t new_size ) {
0 commit comments