Ver Fonte

Further fixes for SQLite3 support

Signed-off-by: Michael Eshom <[email protected]>
Michael Eshom há 10 anos atrás
pai
commit
78ee584f4e
2 ficheiros alterados com 28 adições e 19 exclusões
  1. 27 17
      Sources/Subs-Db-sqlite3.php
  2. 1 2
      other/install.php

+ 27 - 17
Sources/Subs-Db-sqlite3.php

@@ -78,17 +78,7 @@ function smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix,
 	@$connection->exec('PRAGMA short_column_names = 1');
 
 	// Make some user defined functions!
-	
-	$connection->createFunction('unix_timestamp', 'smf_udf_unix_timestamp', 0);
-	$connection->createFunction('inet_aton', 'smf_udf_inet_aton', 1);
-	$connection->createFunction('inet_ntoa', 'smf_udf_inet_ntoa', 1);
-	$connection->createFunction('find_in_set', 'smf_udf_find_in_set', 2);
-	$connection->createFunction('year', 'smf_udf_year', 1);
-	$connection->createFunction('month', 'smf_udf_month', 1);
-	$connection->createFunction('dayofmonth', 'smf_udf_dayofmonth', 1);
-	$connection->createFunction('concat', 'smf_udf_concat');
-	$connection->createFunction('locate', 'smf_udf_locate', 2);
-	$connection->createFunction('regexp', 'smf_udf_regexp', 2);
+	smf_db_define_udfs($connection);
 
 	return $connection;
 }
@@ -112,23 +102,43 @@ function db_extend($type = 'extra')
  * Verify that we have a valid connection
  * 
  * @param resource $connection
- * Thanks to tinoet for this idea
+ * Thanks to tinoest for this idea
  */
 function smf_db_check_connection($connection)
 {
 	global $db_name;
 
- 	if (!is_object($connection))
+ 	if (!is_object($connection) || is_null($connection))
  	{
  		if (substr($db_name, -3) != '.db')
  			$db_name .= '.db';
 
-		$connection = new Sqlite3($connection);
+		$connection = new Sqlite3($db_name);
+
+		smf_db_define_udfs($connection);
 	}
- 	
+
 	return $connection;
 }
 
+/**
+ * Define user-defined functions for SQLite3
+ * @param resource $connection
+ */
+function smf_db_define_udfs(&$connection)
+{
+	$connection->createFunction('unix_timestamp', 'smf_udf_unix_timestamp', 0);
+	$connection->createFunction('inet_aton', 'smf_udf_inet_aton', 1);
+	$connection->createFunction('inet_ntoa', 'smf_udf_inet_ntoa', 1);
+	$connection->createFunction('find_in_set', 'smf_udf_find_in_set', 2);
+	$connection->createFunction('year', 'smf_udf_year', 1);
+	$connection->createFunction('month', 'smf_udf_month', 1);
+	$connection->createFunction('dayofmonth', 'smf_udf_dayofmonth', 1);
+	$connection->createFunction('concat', 'smf_udf_concat');
+	$connection->createFunction('locate', 'smf_udf_locate', 2);
+	$connection->createFunction('regexp', 'smf_udf_regexp', 2);
+}
+
 /**
  * Fix db prefix if necessary.
  * SQLite doesn't actually need this!
@@ -215,7 +225,7 @@ function smf_db_replacement__callback($matches)
 					smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__);
 
 				foreach ($replacement as $key => $value)
-					$replacement[$key] = sprintf('\'%1$s\'', sqlite3::escape_string($value));
+					$replacement[$key] = sprintf('\'%1$s\'', SQLite3::escapeString($value));
 
 				return implode(', ', $replacement);
 			}
@@ -430,7 +440,7 @@ function smf_db_query($identifier, $db_string, $db_values = array(), $connection
 	$ret = @$connection->query($db_string);
 	if ($ret === false && empty($db_values['db_error_skip']))
 	{
-		$err_msg = $ret->lastErrorMsg();
+		$err_msg = $connection->lastErrorMsg();
 		$ret = smf_db_error($db_string . '#!#' . $err_msg, $connection);
 	}
 

+ 1 - 2
other/install.php

@@ -961,8 +961,7 @@ function ForumSettings()
 	$incontext['detected_url'] = 'http' . (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 's' : '') . '://' . $host . substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
 
 	// Check if the database sessions will even work.
-	// DB-driven sessions are borked on SQLite3 for some reason
-	$incontext['test_dbsession'] = (ini_get('session.auto_start') != 1 && $db_type != 'sqlite3');
+	$incontext['test_dbsession'] = (ini_get('session.auto_start') != 1);
 	$incontext['utf8_default'] = $databases[$db_type]['utf8_default'];
 	$incontext['utf8_required'] = $databases[$db_type]['utf8_required'];