From a962f4eb389a3105b2822283d7d78c10522ab026 Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Mon, 5 Jan 2015 13:42:03 +0100 Subject: [PATCH] Added stub for database query profiling. --- includes/db/connect_db.inc | 10 +++++++++- includes/db/connect_db_mysql.inc | 17 ++++++----------- includes/db/connect_db_mysqli.inc | 20 ++++++++------------ sql/alter2.4.php | 3 +-- 4 files changed, 24 insertions(+), 26 deletions(-) diff --git a/includes/db/connect_db.inc b/includes/db/connect_db.inc index 91be72ce..98a18f59 100644 --- a/includes/db/connect_db.inc +++ b/includes/db/connect_db.inc @@ -116,4 +116,12 @@ function db_get_default_charset() return $var[0]; } - +/* + SQL db profiling stub +*/ +if (!function_exists('db_profile')) +{ + function db_profile($sql=false) + { + } +} \ No newline at end of file diff --git a/includes/db/connect_db_mysql.inc b/includes/db/connect_db_mysql.inc index e574362e..6767cb25 100644 --- a/includes/db/connect_db_mysql.inc +++ b/includes/db/connect_db_mysql.inc @@ -46,7 +46,7 @@ function db_query($sql, $err_msg=null) { global $db, $show_sql, $sql_trail, $select_trail, $go_debug, $sql_queries, $Ajax, $db_connections, $db_last_inserted_id; - + // set current db prefix $comp = isset($_SESSION["wa_current_user"]->cur_con) ? $_SESSION["wa_current_user"]->cur_con : 0; $cur_prefix = $db_connections[$comp]['tbpref']; @@ -58,17 +58,12 @@ function db_query($sql, $err_msg=null) $sql_queries .= "
$sql
\n
"; } - // mysql profiling - global $profile_sql; - if (@$profile_sql) - get_usec(); + db_profile(); // mysql profiling + $result = mysql_query($sql, $db); - if (@$profile_sql) - { - $profile_sql= false; - _vd($sql.'
:'.db_num_rows($result).'rows, '.get_usec()); - } - + + db_profile($sql); + if($sql_trail) { $db_last_inserted_id = mysql_insert_id($db); // preserve in case trail insert is done if ($select_trail || (strstr($sql, 'SELECT') === false)) { diff --git a/includes/db/connect_db_mysqli.inc b/includes/db/connect_db_mysqli.inc index c5c1d69b..bb452f2b 100644 --- a/includes/db/connect_db_mysqli.inc +++ b/includes/db/connect_db_mysqli.inc @@ -9,6 +9,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License here . ***********************************************************************/ +define('SQL_MODE', 'STRICT_ALL_TABLES,NO_ZERO_IN_DATE'); function set_global_connection($company=-1) { @@ -32,8 +33,8 @@ function set_global_connection($company=-1) ///// This non empty sql_mode values can interphere with FA, so all is set empty during ///// our sessions. ///// We are, however, investigating the existing code to be compatible in the future. - if (strncmp(db_get_version(), "5.6", 3) >= 0) - db_query("SET sql_mode = ''"); +// if (strncmp(db_get_version(), "5.6", 3) >= 0) + db_query("SET sql_mode = '".SQL_MODE."'"); ///// return $db; } @@ -58,17 +59,12 @@ function db_query($sql, $err_msg=null) $sql_queries .= "
$sql
\n
"; } - // mysql profiling - global $profile_sql; - if (@$profile_sql) - get_usec(); + db_profile(); // mysql profiling + $result = mysqli_query($db, $sql); - if (@$profile_sql) - { - $profile_sql= false; - _vd($sql.'
:'.db_num_rows($result).'rows, '.get_usec()); - } - + + db_profile($sql); + if($sql_trail) { $db_last_inserted_id = mysqli_insert_id($db); // preserve in case trail insert is done if ($select_trail || (strstr($sql, 'SELECT') === false)) { diff --git a/sql/alter2.4.php b/sql/alter2.4.php index 5f87259a..c51f1996 100644 --- a/sql/alter2.4.php +++ b/sql/alter2.4.php @@ -146,7 +146,7 @@ class fa2_4 { // site default encoding is presumed as encoding for all databases! $lang = array_search_value($dflt_lang, $installed_languages, 'code'); $new_encoding = get_mysql_encoding_name(strtoupper($lang['encoding'])); - // get_usec(); + if ($test) error_log('Switching database to utf8 encoding from '.$old_encoding); $collation = get_mysql_collation(); @@ -154,7 +154,6 @@ class fa2_4 { $tresult = db_query($tsql, "Cannot select all tables with prefix '$pref'"); while($tbl = db_fetch($tresult)) { $table = $tbl[0]; - // if ($table != '1_chart_master') continue; _vd($table); get_usec(); // fast debug on single table db_query("ALTER TABLE `$table` CONVERT TO CHARACTER SET $old_encoding"); // convert encoding on utf-8 tables -- 2.30.2