From 1ff3afa42c4ac1977f01d8e199f6f2a8fba28bbd Mon Sep 17 00:00:00 2001 From: Craig Knudsen Date: Tue, 23 Jan 2024 08:45:50 -0500 Subject: [PATCH] Fixes for postgres compatibility --- category_handler.php | 2 +- edit_entry_handler.php | 2 +- includes/dbi4php.php | 23 ++++++++++++----------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/category_handler.php b/category_handler.php index f5cea9fa6..4d030ad29 100644 --- a/category_handler.php +++ b/category_handler.php @@ -71,7 +71,7 @@ function updateIconBlob($catId, $iconData, $iconMimeType) { if (!dbi_execute( 'DELETE FROM webcal_entry_categories WHERE cat_id = ? AND ( cat_owner = ?' - . ($is_admin ? ' OR cat_owner = "" )' : ' )'), + . ($is_admin ? ' OR cat_owner = '' )' : ' )'), [$id, $login] )) { $error = db_error(); diff --git a/edit_entry_handler.php b/edit_entry_handler.php index d0eae6339..e5bdcd6b0 100644 --- a/edit_entry_handler.php +++ b/edit_entry_handler.php @@ -714,7 +714,7 @@ function sort_byday( $a, $b ) { $cat_owner = ( ( ! empty( $user ) && strlen( $user ) ) && ( $is_assistant || $is_admin ) ? $user : $login ); dbi_execute( 'DELETE FROM webcal_entry_categories WHERE cal_id = ? - AND ( cat_owner = ? OR cat_owner = "" )', [$id, $cat_owner] ); + AND ( cat_owner = ? OR cat_owner = ? )', [$id, $cat_owner, ''] ); if( ! empty( $cat_id ) ) { $categories = explode( ',', $cat_id ); diff --git a/includes/dbi4php.php b/includes/dbi4php.php index 354a83c93..553d9b9cf 100644 --- a/includes/dbi4php.php +++ b/includes/dbi4php.php @@ -355,7 +355,7 @@ function dbi_query( $sql, $fatalOnError = true, $showError = true ) { return OCIExecute( $GLOBALS['oracle_statement'], OCI_COMMIT_ON_SUCCESS ); } elseif( strcmp( $GLOBALS['db_type'], 'postgresql' ) == 0 ) { $found_db_type = true; - $res = pg_exec( $GLOBALS['postgresql_connection'], $sql ); + $res = @pg_exec( $GLOBALS['postgresql_connection'], $sql ); } elseif( strcmp( $GLOBALS['db_type'], 'sqlite' ) == 0 ) { $found_db_type = true; $res = sqlite_query( $GLOBALS['sqlite_c'], $sql, SQLITE_NUM ); @@ -367,9 +367,12 @@ function dbi_query( $sql, $fatalOnError = true, $showError = true ) { if( $found_db_type ) { if( ! $res ) { //echo "Db error: " . dbi_error() . "
\n"; - dbi_fatal_error( translate( 'Error executing query.' ) - . ( $phpdbiVerbose ? ( dbi_error() . "\n\n
\n" . $sql ) : '' ), - $fatalOnError, $showError ); + $verboseDetails = empty($phpdbiVerbose) ? '' : ('

' . dbi_error() . "\n\n
\n" . $sql); + dbi_fatal_error( + translate('Error executing query.') . $verboseDetails, + $fatalOnError, + $showError + ); } return $res; } else @@ -594,7 +597,8 @@ function dbi_free_result($res) } return true; // Assuming a successful operation as it's not directly supported. case 'postgresql': - return pg_freeresult($res); + pg_query_params($GLOBALS['postgresql_connection'], 'SELECT 1', []); // auto-free query + return true; case 'sqlite': // Not supported for SQLite, just return true. return true; @@ -638,7 +642,7 @@ function dbi_error() return htmlentities($e['message']); case 'postgresql': - return pg_errormessage($GLOBALS['postgresql_connection']); + return pg_last_error($GLOBALS['postgresql_connection']); case 'sqlite': if (empty($GLOBALS['db_sqlite_error_str'])) { @@ -707,7 +711,7 @@ function dbi_escape_string( $string ) { ? addslashes( $string ) : $db_connection_info['connection']->real_escape_string( $string ) ); case 'postgresql': - return pg_escape_string( $string ); + return pg_escape_string( $GLOBALS['postgresql_connection'], $string ); case 'sqlite': return sqlite_escape_string( $string ); case 'sqlite3': @@ -740,10 +744,7 @@ function dbi_escape_string( $string ) { * to the {@link dbi_fetch_row()} function to obtain the * results), or true/false on insert or delete queries. */ -function dbi_execute ( $sql, $params = [], $fatalOnError = true, - $showError = true ) { - - //echo "SQL: $sql
\n"; +function dbi_execute($sql, $params = [], $fatalOnError = true, $showError = true) { if( count( $params ) == 0 ) return dbi_query( $sql, $fatalOnError, $showError );