Fixed some bugs and revised the documentations
git-svn-id: https://plugins.svn.wordpress.org/sqlite-integration/trunk@847560 b8457f37-d9ea-0310-8a92-e5e31aec5664
This commit is contained in:
parent
8c2258e7ee
commit
22a658ac3a
35
db.php
35
db.php
|
@ -1,11 +1,12 @@
|
|||
<?php
|
||||
/**
|
||||
* This file must be placed in the directory
|
||||
* This file defines some constant required for SQLite Integration.
|
||||
*
|
||||
* wordpress/wp-content/db.php
|
||||
* This file must be placed in the directory wordpress/wp-content/db.php.
|
||||
* WordPress loads this file automatically.
|
||||
*
|
||||
* @package SQLite Integration
|
||||
* @author Kojima Toshiyasu, Justin Adie
|
||||
* @author Kojima Toshiyasu
|
||||
*
|
||||
*/
|
||||
if (!defined('ABSPATH')) { // Oh, you are not WordPress!
|
||||
|
@ -13,11 +14,13 @@ if (!defined('ABSPATH')) { // Oh, you are not WordPress!
|
|||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notice:
|
||||
/*
|
||||
* USE_MYSQL is a directive for using MySQL for database.
|
||||
* If you want to change the database from SQLite to MySQL or from MySQL to SQLite,
|
||||
* the line below in the wp-config.php will enable you to use MySQL.
|
||||
* <code>
|
||||
* define('USE_MYSQL', true);
|
||||
* </code>
|
||||
*/
|
||||
if (defined('USE_MYSQL') && USE_MYSQL === true) return;
|
||||
|
||||
|
@ -35,7 +38,7 @@ function pdo_log_error($message, $data = null) {
|
|||
<head>
|
||||
<title>WordPress › Error</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<link rel="stylesheet" href="{$admin_dir}install.css" type="text/css" />
|
||||
<link rel="stylesheet" href="{$admin_dir}css/install.css" type="text/css" />
|
||||
</head>
|
||||
<body>
|
||||
<h1 id="logo"><img alt="WordPress" src="{$admin_dir}images/wordpress-logo.png" /></h1>
|
||||
|
@ -60,13 +63,17 @@ if (!extension_loaded('pdo_sqlite')) {
|
|||
pdo_log_error('PDO Driver for SQLite is missing.', 'Your PHP installtion appears not to have the right PDO drivers loaded. These are required for this version of WordPress and the type of database you have specified.');
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Notice:
|
||||
* Your scripts have the permission to create directories or files on your server.
|
||||
* If you write in your wp-config.php like below, we take these definitions.
|
||||
* define('DB_DIR', '/full_path_to_the_database_directory/');
|
||||
* define('DB_FILE', 'database_file_name');
|
||||
*/
|
||||
|
||||
/*
|
||||
* PDODIR is SQLite Integration installed directory.
|
||||
*/
|
||||
if (defined('WP_PLUGIN_DIR')) {
|
||||
define('PDODIR', WP_PLUGIN_DIR . '/sqlite-integration/');
|
||||
} else {
|
||||
|
@ -76,7 +83,10 @@ if (defined('WP_PLUGIN_DIR')) {
|
|||
define('PDODIR', ABSPATH . 'wp-content/plugins/sqlite-integration/');
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* FQDBDIR is a directory where the sqlite database file is placed.
|
||||
* If DB_DIR is defined, it is used as FQDBDIR.
|
||||
*/
|
||||
if (defined('DB_DIR')) {
|
||||
if (substr(DB_DIR, -1, 1) != '/') {
|
||||
define('FQDBDIR', DB_DIR . '/');
|
||||
|
@ -90,13 +100,18 @@ if (defined('DB_DIR')) {
|
|||
define('FQDBDIR', ABSPATH . 'wp-content/database/');
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* FQDB is a database file name. If DB_FILE is defined, it is used
|
||||
* as FQDB.
|
||||
*/
|
||||
if ( defined('DB_FILE' )) {
|
||||
define('FQDB', FQDBDIR . DB_FILE);
|
||||
} else {
|
||||
define('FQDB', FQDBDIR . '.ht.sqlite');
|
||||
}
|
||||
|
||||
/*
|
||||
* UDF_FILE is a file that contains user defined functions.
|
||||
*/
|
||||
if (version_compare(PHP_VERSION, '5.3', '<')) {
|
||||
define('UDF_FILE', PDODIR . 'functions-5-2.php');
|
||||
} elseif (version_compare(PHP_VERSION, '5.3', '>=')) {
|
||||
|
|
|
@ -1,23 +1,48 @@
|
|||
<?php
|
||||
/**
|
||||
* This file contains the class that defines user defined functions for PDO library.
|
||||
*
|
||||
* This file is for PHP 5.2.x or lesser. For PHP 5.3.x or later, functions.php is
|
||||
* loaded. PHP version is checked in the db.php and that will load the apropriate
|
||||
* one.
|
||||
*
|
||||
* @package SQLite Integration
|
||||
* @author Kojima Toshiyasu, Justin Adie
|
||||
* @author Kojima Toshiyasu
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class defines user defined functions(UDFs) for PDO
|
||||
* This replaces the functions used in the SQL statement with the PHP functions.
|
||||
* If you want another, add the name in the array and define the function with
|
||||
* PHP script.
|
||||
* This class defines user defined functions(UDFs) for PDO library.
|
||||
*
|
||||
* These functions replace those used in the SQL statement with the PHP functions.
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* <code>
|
||||
* new PDOSQLiteUDFS(ref_to_pdo_obj);
|
||||
* </code>
|
||||
*
|
||||
* This automatically enables ref_to_pdo_obj to replace the function in the SQL statement
|
||||
* to the ones defined here.
|
||||
*/
|
||||
class PDOSQLiteUDFS {
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Initialize the user defined functions to the PDO object with PDO::sqliteCreateFunction().
|
||||
*
|
||||
* @param reference to PDO object $pdo
|
||||
*/
|
||||
public function __construct(&$pdo){
|
||||
foreach ($this->functions as $f=>$t) {
|
||||
$pdo->sqliteCreateFunction($f, array($this, $t));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Array to associate MySQL function to the substituted one.
|
||||
*
|
||||
* @var associative array
|
||||
*/
|
||||
private $functions = array(
|
||||
'month' => 'month',
|
||||
'year' => 'year',
|
||||
|
@ -41,7 +66,6 @@ class PDOSQLiteUDFS {
|
|||
'subdate' => 'date_sub',
|
||||
'localtime' => 'now',
|
||||
'localtimestamp' => 'now',
|
||||
//'date'=>'date',
|
||||
'isnull' => 'isnull',
|
||||
'if' => '_if',
|
||||
'regexpp' => 'regexp',
|
||||
|
@ -49,6 +73,7 @@ class PDOSQLiteUDFS {
|
|||
'field' => 'field',
|
||||
'log' => 'log',
|
||||
'least' => 'least',
|
||||
'greatest' => 'greatest',
|
||||
'get_lock' => 'get_lock',
|
||||
'release_lock' => 'release_lock',
|
||||
'ucase' => 'ucase',
|
||||
|
@ -59,34 +84,86 @@ class PDOSQLiteUDFS {
|
|||
'locate' => 'locate',
|
||||
'version' => 'version'
|
||||
);
|
||||
|
||||
/**
|
||||
* Method to extract the month value from the date.
|
||||
*
|
||||
* @param string representing the date formated as 0000-00-00.
|
||||
* @return string representing the number of the month between 1 and 12.
|
||||
*/
|
||||
public function month($field){
|
||||
$t = strtotime($field);
|
||||
return date('n', $t);
|
||||
}
|
||||
/**
|
||||
* Method to extract the year value from the date.
|
||||
*
|
||||
* @param string representing the date formated as 0000-00-00.
|
||||
* @return string representing the number of the year.
|
||||
*/
|
||||
public function year($field){
|
||||
$t = strtotime($field);
|
||||
return date('Y', $t);
|
||||
}
|
||||
/**
|
||||
* Method to extract the day value from the date.
|
||||
*
|
||||
* @param string representing the date formated as 0000-00-00.
|
||||
* @return string representing the number of the day of the month from 1 and 31.
|
||||
*/
|
||||
public function day($field){
|
||||
$t = strtotime($field);
|
||||
return date('j', $t);
|
||||
}
|
||||
/**
|
||||
* Method to return the unix timestamp.
|
||||
*
|
||||
* Used without an argument, it returns PHP time() function (total seconds passed
|
||||
* from '1970-01-01 00:00:00' GMT). Used with the argument, it changes the value
|
||||
* to the timestamp.
|
||||
*
|
||||
* @param string representing the date formated as '0000-00-00 00:00:00'.
|
||||
* @return number of unsigned integer
|
||||
*/
|
||||
public function unix_timestamp($field = null){
|
||||
return is_null($field) ? time() : strtotime($field);
|
||||
}
|
||||
/**
|
||||
* Method to emulate MySQL SECOND() function.
|
||||
*
|
||||
* @param string representing the time formated as '00:00:00'.
|
||||
* @return number of unsigned integer
|
||||
*/
|
||||
public function second($field){
|
||||
$t = strtotime($field);
|
||||
return intval( date("s", $t) );
|
||||
}
|
||||
/**
|
||||
* Method to emulate MySQL MINUTE() function.
|
||||
*
|
||||
* @param string representing the time formated as '00:00:00'.
|
||||
* @return number of unsigned integer
|
||||
*/
|
||||
public function minute($field){
|
||||
$t = strtotime($field);
|
||||
return intval(date("i", $t));
|
||||
}
|
||||
/**
|
||||
* Method to emulate MySQL HOUR() function.
|
||||
*
|
||||
* @param string representing the time formated as '00:00:00'.
|
||||
* @return number
|
||||
*/
|
||||
public function hour($time){
|
||||
list($hours, $minutes, $seconds) = explode(":", $time);
|
||||
return intval($hours);
|
||||
}
|
||||
/**
|
||||
* Method to emulate MySQL FROM_UNIXTIME() function.
|
||||
*
|
||||
* @param integer of unix timestamp
|
||||
* @param string to indicate the way of formatting(optional)
|
||||
* @return string formatted as '0000-00-00 00:00:00'.
|
||||
*/
|
||||
public function from_unixtime($field, $format=null){
|
||||
// $field is a timestamp
|
||||
//convert to ISO time
|
||||
|
@ -95,25 +172,75 @@ class PDOSQLiteUDFS {
|
|||
|
||||
return is_null($format) ? $date : $self->dateformat($date, $format);
|
||||
}
|
||||
/**
|
||||
* Method to emulate MySQL NOW() function.
|
||||
*
|
||||
* @return string representing current time formatted as '0000-00-00 00:00:00'.
|
||||
*/
|
||||
public function now(){
|
||||
return date("Y-m-d H:i:s");
|
||||
}
|
||||
/**
|
||||
* Method to emulate MySQL CURDATE() function.
|
||||
*
|
||||
* @return string representing current time formatted as '0000-00-00'.
|
||||
*/
|
||||
public function curdate() {
|
||||
return date("Y-m-d");
|
||||
}
|
||||
/**
|
||||
* Method to emulate MySQL CHAR_LENGTH() function.
|
||||
*
|
||||
* @param string
|
||||
* @return unsigned integer for the length of the argument.
|
||||
*/
|
||||
public function char_length($field){
|
||||
return strlen($field);
|
||||
}
|
||||
/**
|
||||
* Method to emulate MySQL MD5() function.
|
||||
*
|
||||
* @param string
|
||||
* @return string of the md5 hash value of the argument.
|
||||
*/
|
||||
public function md5($field){
|
||||
return md5($field);
|
||||
}
|
||||
/**
|
||||
* Method to emulate MySQL RAND() function.
|
||||
*
|
||||
* SQLite does have a random generator, but it is called RANDOM() and returns random
|
||||
* number between -9223372036854775808 and +9223372036854775807. So we substitute it
|
||||
* with PHP random generator.
|
||||
*
|
||||
* This function uses mt_rand() which is four times faster than rand() and returns
|
||||
* the random number between 0 and 1.
|
||||
*
|
||||
* @return unsigned integer
|
||||
*/
|
||||
public function rand(){
|
||||
return rand(0,1);
|
||||
return mt_rand(0,1);
|
||||
}
|
||||
/**
|
||||
* Method to emulate MySQL SUBSTRING() function.
|
||||
*
|
||||
* This function rewrites the function name to SQLite compatible substr().
|
||||
*
|
||||
* @param string $text
|
||||
* @param integer $pos representing the start point.
|
||||
* @param integer $len representing the length of the substring(optional).
|
||||
* @return string
|
||||
*/
|
||||
public function substring($text, $pos, $len=null){
|
||||
if (is_null($len)) return substr($text, $pos-1);
|
||||
else return substr($text, $pos-1, $len);
|
||||
return "substr($text, $pos, $len)";
|
||||
}
|
||||
/**
|
||||
* Method to emulate MySQL DATEFORMAT() function.
|
||||
*
|
||||
* @param string date formatted as '0000-00-00' or datetime as '0000-00-00 00:00:00'.
|
||||
* @param string $format
|
||||
* @return string formatted according to $format
|
||||
*/
|
||||
public function dateformat($date, $format){
|
||||
$mysql_php_dateformats = array ( '%a' => 'D', '%b' => 'M', '%c' => 'n', '%D' => 'jS', '%d' => 'd', '%e' => 'j', '%H' => 'H', '%h' => 'h', '%I' => 'h', '%i' => 'i', '%j' => 'z', '%k' => 'G', '%l' => 'g', '%M' => 'F', '%m' => 'm', '%p' => 'A', '%r' => 'h:i:s A', '%S' => 's', '%s' => 's', '%T' => 'H:i:s', '%U' => 'W', '%u' => 'W', '%V' => 'W', '%v' => 'W', '%W' => 'l', '%w' => 'w', '%X' => 'Y', '%x' => 'o', '%Y' => 'Y', '%y' => 'y', );
|
||||
$t = strtotime($date);
|
||||
|
@ -121,6 +248,17 @@ class PDOSQLiteUDFS {
|
|||
$output = date($format, $t);
|
||||
return $output;
|
||||
}
|
||||
/**
|
||||
* Method to emulate MySQL DATE_ADD() function.
|
||||
*
|
||||
* This function adds the time value of $interval expression to $date.
|
||||
* $interval is a single quoted strings rewritten by SQLiteQueryDriver::rewrite_query().
|
||||
* It is calculated in the private function deriveInterval().
|
||||
*
|
||||
* @param string $date representing the start date.
|
||||
* @param string $interval representing the expression of the time to add.
|
||||
* @return string date formated as '0000-00-00 00:00:00'.
|
||||
*/
|
||||
public function date_add($date, $interval) {
|
||||
$interval = $this->deriveInterval($interval);
|
||||
switch (strtolower($date)) {
|
||||
|
@ -141,6 +279,17 @@ class PDOSQLiteUDFS {
|
|||
}
|
||||
return $returnval;
|
||||
}
|
||||
/**
|
||||
* Method to emulate MySQL DATE_SUB() function.
|
||||
*
|
||||
* This function substracts the time value of $interval expression from $date.
|
||||
* $interval is a single quoted strings rewritten by SQLiteQueryDriver::rewrite_query().
|
||||
* It is calculated in the private function deriveInterval().
|
||||
*
|
||||
* @param string $date representing the start date.
|
||||
* @param string $interval representing the expression of the time to substract.
|
||||
* @return string date formated as '0000-00-00 00:00:00'.
|
||||
*/
|
||||
public function date_sub($date, $interval) {
|
||||
$interval = $this->deriveInterval($interval);
|
||||
switch (strtolower($date)) {
|
||||
|
@ -161,7 +310,13 @@ class PDOSQLiteUDFS {
|
|||
}
|
||||
return $returnval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to calculate the interval time between two dates value.
|
||||
*
|
||||
* @access private
|
||||
* @param string $interval white space separated expression.
|
||||
* @return string representing the time to add or substract.
|
||||
*/
|
||||
private function deriveInterval($interval){
|
||||
$interval = trim(substr(trim($interval), 8));
|
||||
$parts = explode(' ', $interval);
|
||||
|
@ -252,25 +407,60 @@ class PDOSQLiteUDFS {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to emulate MySQL DATE() function.
|
||||
*
|
||||
* @param string $date formatted as unix time.
|
||||
* @return string formatted as '0000-00-00'.
|
||||
*/
|
||||
public function date($date){
|
||||
return date("Y-m-d", strtotime($date));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to emulate MySQL ISNULL() function.
|
||||
*
|
||||
* This function returns true if the argument is null, and true if not.
|
||||
*
|
||||
* @param various types $field
|
||||
* @return boolean
|
||||
*/
|
||||
public function isnull($field){
|
||||
return is_null($field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to emulate MySQL IF() function.
|
||||
*
|
||||
* As 'IF' is a reserved word for PHP, function name must be changed.
|
||||
*
|
||||
* @param unknonw $expression the statement to be evaluated as true or false.
|
||||
* @param unknown $true statement or value returned if $expression is true.
|
||||
* @param unknown $false statement or value returned if $expression is false.
|
||||
* @return unknown
|
||||
*/
|
||||
public function _if($expression, $true, $false){
|
||||
return ($expression == true) ? $true : $false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to emulate MySQL REGEXP() function.
|
||||
*
|
||||
* @param string $field haystack
|
||||
* @param string $pattern: regular expression to match.
|
||||
* @return integer 1 if matched, 0 if not matched.
|
||||
*/
|
||||
public function regexp($field, $pattern){
|
||||
$pattern = str_replace('/', '\/', $pattern);
|
||||
$pattern = "/" . $pattern ."/i";
|
||||
return preg_match ($pattern, $field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to emulate MySQL CONCAT() function.
|
||||
*
|
||||
* SQLite does have CONCAT() function, but it has a different syntax from MySQL.
|
||||
* So this function must be manipulated here.
|
||||
*
|
||||
* @param string
|
||||
* @return NULL if the argument is null | string conatenated if the argument is given.
|
||||
*/
|
||||
public function concat() {
|
||||
$returnValue = "";
|
||||
$argsNum = func_num_args();
|
||||
|
@ -283,20 +473,48 @@ class PDOSQLiteUDFS {
|
|||
}
|
||||
return $returnValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to emulate MySQL FIELD() function.
|
||||
*
|
||||
* This function gets the list argument and compares the first item to all the others.
|
||||
* If the same value is found, it returns the position of that value. If not, it
|
||||
* returns 0.
|
||||
*
|
||||
* @param variable number of string, integer or double
|
||||
* @return unsigned integer
|
||||
*/
|
||||
public function field() {
|
||||
$numArgs = func_num_args();
|
||||
if ($numArgs < 2 or is_null(func_get_arg(0))) {
|
||||
return null;
|
||||
return 0;
|
||||
}
|
||||
$arr = func_get_args();
|
||||
$searchString = strtolower(array_shift($arr));
|
||||
for ($i = 0; $i < $numArgs-1; $i++) {
|
||||
if ($searchString === strtolower($arr[$i])) return $i + 1;
|
||||
}
|
||||
return null;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to emulate MySQL LOG() function.
|
||||
*
|
||||
* Used with one argument, it returns the natural logarithm of X.
|
||||
* <code>
|
||||
* LOG(X)
|
||||
* </code>
|
||||
* Used with two arguments, it returns the natural logarithm of X base B.
|
||||
* <code>
|
||||
* LOG(B, X)
|
||||
* </code>
|
||||
* In this case, it returns the value of log(X) / log(B).
|
||||
*
|
||||
* Used without an argument, it returns false. This returned value will be
|
||||
* rewritten to 0, because SQLite doesn't understand true/false value.
|
||||
*
|
||||
* @param integer representing the base of the logarithm, which is optional.
|
||||
* @param double value to turn into logarithm.
|
||||
* @return double | NULL
|
||||
*/
|
||||
public function log() {
|
||||
$numArgs = func_num_args();
|
||||
if ($numArgs == 1) {
|
||||
|
@ -307,18 +525,36 @@ class PDOSQLiteUDFS {
|
|||
$arg2 = func_get_arg(1);
|
||||
return log($arg1)/log($arg2);
|
||||
} else {
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function least() {
|
||||
$arr = func_get_args();
|
||||
return min($arr);
|
||||
}
|
||||
|
||||
/**
|
||||
* These two functions are meaningless in SQLite
|
||||
* So we return meaningless statement and do nothing
|
||||
* Method to emulate MySQL LEAST() function.
|
||||
*
|
||||
* This function rewrites the function name to SQLite compatible function name.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function least() {
|
||||
$arg_list = func_get_args();
|
||||
return "min($arg_list)";
|
||||
}
|
||||
/**
|
||||
* Method to emulate MySQL GREATEST() function.
|
||||
*
|
||||
* This function rewrites the function name to SQLite compatible function name.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function greatest() {
|
||||
$arg_list = func_get_args();
|
||||
return "max($arg_list)";
|
||||
}
|
||||
/**
|
||||
* Method to dummy out MySQL GET_LOCK() function.
|
||||
*
|
||||
* This function is meaningless in SQLite, so we do nothing.
|
||||
*
|
||||
* @param string $name
|
||||
* @param integer $timeout
|
||||
* @return string
|
||||
|
@ -326,39 +562,75 @@ class PDOSQLiteUDFS {
|
|||
public function get_lock($name, $timeout) {
|
||||
return '1=1';
|
||||
}
|
||||
/**
|
||||
* Method to dummy out MySQL RELEASE_LOCK() function.
|
||||
*
|
||||
* This function is meaningless in SQLite, so we do nothing.
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
public function release_lock($name) {
|
||||
return '1=1';
|
||||
}
|
||||
|
||||
/**
|
||||
* MySQL aliases for upper and lower functions
|
||||
* @param unknown $string
|
||||
* @return string
|
||||
* Method to emulate MySQL UCASE() function.
|
||||
*
|
||||
* This is MySQL alias for upper() function. This function rewrites it
|
||||
* to SQLite compatible name upper().
|
||||
*
|
||||
* @param string
|
||||
* @return string SQLite compatible function name.
|
||||
*/
|
||||
public function ucase($string) {
|
||||
return "upper($string)";
|
||||
}
|
||||
/**
|
||||
* Method to emulate MySQL LCASE() function.
|
||||
*
|
||||
* This is MySQL alias for lower() function. This function rewrites it
|
||||
* to SQLite compatible name lower().
|
||||
*
|
||||
* @param string
|
||||
* @return string SQLite compatible function name.
|
||||
*/
|
||||
public function lcase($string) {
|
||||
return "lower($string)";
|
||||
}
|
||||
|
||||
/**
|
||||
* MySQL aliases for INET_NTOA and INET_ATON functions
|
||||
* @param unsigned integer, string respectively
|
||||
* @return string, unsigned integer respectively
|
||||
* Method to emulate MySQL INET_NTOA() function.
|
||||
*
|
||||
* This function gets 4 or 8 bytes integer and turn it into the network address.
|
||||
*
|
||||
* @param unsigned long integer
|
||||
* @return string
|
||||
*/
|
||||
public function inet_ntoa($num) {
|
||||
return long2ip($num);
|
||||
}
|
||||
/**
|
||||
* Method to emulate MySQL INET_ATON() function.
|
||||
*
|
||||
* This function gets the network address and turns it into integer.
|
||||
*
|
||||
* @param string
|
||||
* @return unsigned long integer
|
||||
*/
|
||||
public function inet_aton($addr) {
|
||||
$int_data = ip2long($addr);
|
||||
$unsigned_int_data = sprintf('%u', $address);
|
||||
return $unsigned_int_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* MySQL aliase for DATEDIFF function
|
||||
* @param string, string
|
||||
* Method to emulate MySQL DATEDIFF() function.
|
||||
*
|
||||
* This function compares two dates value and returns the difference.
|
||||
*
|
||||
* PHP 5.3.2 has a serious bug in DateTime::diff(). So if users' PHP is that version,
|
||||
* we don't use that function. See https://bugs.php.net/bug.php?id=51184.
|
||||
*
|
||||
* @param string start
|
||||
* @param string end
|
||||
* @return string
|
||||
*/
|
||||
public function datediff($start, $end) {
|
||||
|
@ -368,7 +640,16 @@ class PDOSQLiteUDFS {
|
|||
return $interval;
|
||||
}
|
||||
/**
|
||||
* emulates MySQL LOCATE() function
|
||||
* Method to emulate MySQL LOCATE() function.
|
||||
*
|
||||
* This function returns the position if $substr is found in $str. If not,
|
||||
* it returns 0. If mbstring extension is loaded, mb_strpos() function is
|
||||
* used.
|
||||
*
|
||||
* @param string needle
|
||||
* @param string haystack
|
||||
* @param integer position
|
||||
* @return integer
|
||||
*/
|
||||
public function locate($substr, $str, $pos = 0) {
|
||||
if (!extension_loaded('mbstring')) {
|
||||
|
@ -386,7 +667,13 @@ class PDOSQLiteUDFS {
|
|||
}
|
||||
}
|
||||
/**
|
||||
* Method to return MySQL version.
|
||||
*
|
||||
* This function only returns WordPress $required_mysql_version, because it is
|
||||
* meaningless for SQLite database.
|
||||
*
|
||||
* @param none
|
||||
* @return string representing the version number
|
||||
*/
|
||||
public function version() {
|
||||
global $required_mysql_version;
|
||||
|
|
410
functions.php
410
functions.php
|
@ -1,23 +1,50 @@
|
|||
<?php
|
||||
/**
|
||||
* This file contains the class that defines user defined functions for PDO library.
|
||||
*
|
||||
* This file is for PHP 5.3.x or later. For PHP 5.2.x or lesser, functions-5-2.php is
|
||||
* loaded. PHP version is checked in the db.php and that will load the apropriate
|
||||
* one.
|
||||
*
|
||||
* @package SQLite Integration
|
||||
* @author Kojima Toshiyasu, Justin Adie
|
||||
* @author Kojima Toshiyasu
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class defines user defined functions(UDFs) for PDO
|
||||
* This replaces the functions used in the SQL statement with the PHP functions.
|
||||
* If you want another, add the name in the array and define the function with
|
||||
* PHP script.
|
||||
* This class defines user defined functions(UDFs) for PDO library.
|
||||
*
|
||||
* These functions replace those used in the SQL statement with the PHP functions.
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* <code>
|
||||
* new PDOSQLiteUDFS(ref_to_pdo_obj);
|
||||
* </code>
|
||||
*
|
||||
* This automatically enables ref_to_pdo_obj to replace the function in the SQL statement
|
||||
* to the ones defined here.
|
||||
*/
|
||||
class PDOSQLiteUDFS {
|
||||
/**
|
||||
* The class constructor
|
||||
*
|
||||
* Initializes the use defined functions to PDO object with PDO::sqliteCreateFunction().
|
||||
*
|
||||
* @param reference to PDO object $pdo
|
||||
*/
|
||||
public function __construct(&$pdo){
|
||||
foreach ($this->functions as $f=>$t) {
|
||||
$pdo->sqliteCreateFunction($f, array($this, $t));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* array to define MySQL function => function defined with PHP.
|
||||
*
|
||||
* Replaced functions must be public.
|
||||
*
|
||||
* @var associative array
|
||||
*/
|
||||
private $functions = array(
|
||||
'month' => 'month',
|
||||
'year' => 'year',
|
||||
|
@ -41,7 +68,6 @@ class PDOSQLiteUDFS {
|
|||
'subdate' => 'date_sub',
|
||||
'localtime' => 'now',
|
||||
'localtimestamp' => 'now',
|
||||
//'date'=>'date',
|
||||
'isnull' => 'isnull',
|
||||
'if' => '_if',
|
||||
'regexpp' => 'regexp',
|
||||
|
@ -49,7 +75,7 @@ class PDOSQLiteUDFS {
|
|||
'field' => 'field',
|
||||
'log' => 'log',
|
||||
'least' => 'least',
|
||||
'replace' => 'replace',
|
||||
'greatest' => 'greatest',
|
||||
'get_lock' => 'get_lock',
|
||||
'release_lock' => 'release_lock',
|
||||
'ucase' => 'ucase',
|
||||
|
@ -60,108 +86,238 @@ class PDOSQLiteUDFS {
|
|||
'locate' => 'locate',
|
||||
'version' => 'version'
|
||||
);
|
||||
|
||||
/**
|
||||
* Method to extract the month value from the date.
|
||||
*
|
||||
* @param string representing the date formated as 0000-00-00.
|
||||
* @return string representing the number of the month between 1 and 12.
|
||||
*/
|
||||
public function month($field){
|
||||
$t = strtotime($field);
|
||||
return date('n', $t);
|
||||
}
|
||||
/**
|
||||
* Method to extract the year value from the date.
|
||||
*
|
||||
* @param string representing the date formated as 0000-00-00.
|
||||
* @return string representing the number of the year.
|
||||
*/
|
||||
public function year($field){
|
||||
$t = strtotime($field);
|
||||
return date('Y', $t);
|
||||
}
|
||||
/**
|
||||
* Method to extract the day value from the date.
|
||||
*
|
||||
* @param string representing the date formated as 0000-00-00.
|
||||
* @return string representing the number of the day of the month from 1 and 31.
|
||||
*/
|
||||
public function day($field){
|
||||
$t = strtotime($field);
|
||||
return date('j', $t);
|
||||
}
|
||||
/**
|
||||
* Method to return the unix timestamp.
|
||||
*
|
||||
* Used without an argument, it returns PHP time() function (total seconds passed
|
||||
* from '1970-01-01 00:00:00' GMT). Used with the argument, it changes the value
|
||||
* to the timestamp.
|
||||
*
|
||||
* @param string representing the date formated as '0000-00-00 00:00:00'.
|
||||
* @return number of unsigned integer
|
||||
*/
|
||||
public function unix_timestamp($field = null){
|
||||
return is_null($field) ? time() : strtotime($field);
|
||||
}
|
||||
/**
|
||||
* Method to emulate MySQL SECOND() function.
|
||||
*
|
||||
* @param string representing the time formated as '00:00:00'.
|
||||
* @return number of unsigned integer
|
||||
*/
|
||||
public function second($field){
|
||||
$t = strtotime($field);
|
||||
return intval( date("s", $t) );
|
||||
}
|
||||
/**
|
||||
* Method to emulate MySQL MINUTE() function.
|
||||
*
|
||||
* @param string representing the time formated as '00:00:00'.
|
||||
* @return number of unsigned integer
|
||||
*/
|
||||
public function minute($field){
|
||||
$t = strtotime($field);
|
||||
return intval(date("i", $t));
|
||||
}
|
||||
/**
|
||||
* Method to emulate MySQL HOUR() function.
|
||||
*
|
||||
* @param string representing the time formated as '00:00:00'.
|
||||
* @return number
|
||||
*/
|
||||
public function hour($time){
|
||||
list($hours, $minutes, $seconds) = explode(":", $time);
|
||||
return intval($hours);
|
||||
}
|
||||
/**
|
||||
* Method to emulate MySQL FROM_UNIXTIME() function.
|
||||
*
|
||||
* @param integer of unix timestamp
|
||||
* @param string to indicate the way of formatting(optional)
|
||||
* @return string formatted as '0000-00-00 00:00:00'.
|
||||
*/
|
||||
public function from_unixtime($field, $format=null){
|
||||
// $field is a timestamp
|
||||
//convert to ISO time
|
||||
$date = date("Y-m-d H:i:s", $field);
|
||||
//now submit to dateformat
|
||||
|
||||
return is_null($format) ? $date : $self->dateformat($date, $format);
|
||||
}
|
||||
/**
|
||||
* Method to emulate MySQL NOW() function.
|
||||
*
|
||||
* @return string representing current time formatted as '0000-00-00 00:00:00'.
|
||||
*/
|
||||
public function now(){
|
||||
return date("Y-m-d H:i:s");
|
||||
}
|
||||
/**
|
||||
* Method to emulate MySQL CURDATE() function.
|
||||
*
|
||||
* @return string representing current time formatted as '0000-00-00'.
|
||||
*/
|
||||
public function curdate() {
|
||||
return date("Y-m-d");
|
||||
}
|
||||
/**
|
||||
* Method to emulate MySQL CHAR_LENGTH() function.
|
||||
*
|
||||
* @param string
|
||||
* @return unsigned integer for the length of the argument.
|
||||
*/
|
||||
public function char_length($field){
|
||||
return strlen($field);
|
||||
}
|
||||
/**
|
||||
* Method to emulate MySQL MD5() function.
|
||||
*
|
||||
* @param string
|
||||
* @return string of the md5 hash value of the argument.
|
||||
*/
|
||||
public function md5($field){
|
||||
return md5($field);
|
||||
}
|
||||
/**
|
||||
* Method to emulate MySQL RAND() function.
|
||||
*
|
||||
* SQLite does have a random generator, but it is called RANDOM() and returns random
|
||||
* number between -9223372036854775808 and +9223372036854775807. So we substitute it
|
||||
* with PHP random generator.
|
||||
*
|
||||
* This function uses mt_rand() which is four times faster than rand() and returns
|
||||
* the random number between 0 and 1.
|
||||
*
|
||||
* @return unsigned integer
|
||||
*/
|
||||
public function rand(){
|
||||
return rand(0,1);
|
||||
return mt_rand(0, 1);
|
||||
}
|
||||
/**
|
||||
* Method to emulate MySQL SUBSTRING() function.
|
||||
*
|
||||
* This function rewrites the function name to SQLite compatible substr().
|
||||
*
|
||||
* @param string $text
|
||||
* @param integer $pos representing the start point.
|
||||
* @param integer $len representing the length of the substring(optional).
|
||||
* @return string
|
||||
*/
|
||||
public function substring($text, $pos, $len=null){
|
||||
if (is_null($len)) return substr($text, $pos-1);
|
||||
else return substr($text, $pos-1, $len);
|
||||
return "substr($text, $pos, $len)";
|
||||
}
|
||||
/**
|
||||
* Method to emulate MySQL DATEFORMAT() function.
|
||||
*
|
||||
* @param string date formatted as '0000-00-00' or datetime as '0000-00-00 00:00:00'.
|
||||
* @param string $format
|
||||
* @return string formatted according to $format
|
||||
*/
|
||||
public function dateformat($date, $format){
|
||||
$mysql_php_dateformats = array ( '%a' => 'D', '%b' => 'M', '%c' => 'n', '%D' => 'jS', '%d' => 'd', '%e' => 'j', '%H' => 'H', '%h' => 'h', '%I' => 'h', '%i' => 'i', '%j' => 'z', '%k' => 'G', '%l' => 'g', '%M' => 'F', '%m' => 'm', '%p' => 'A', '%r' => 'h:i:s A', '%S' => 's', '%s' => 's', '%T' => 'H:i:s', '%U' => 'W', '%u' => 'W', '%V' => 'W', '%v' => 'W', '%W' => 'l', '%w' => 'w', '%X' => 'Y', '%x' => 'o', '%Y' => 'Y', '%y' => 'y', );
|
||||
$t = strtotime($date);
|
||||
$t = strtotime($date);
|
||||
$format = strtr($format, $mysql_php_dateformats);
|
||||
$output = date($format, $t);
|
||||
return $output;
|
||||
}
|
||||
/**
|
||||
* Method to emulate MySQL DATE_ADD() function.
|
||||
*
|
||||
* This function adds the time value of $interval expression to $date.
|
||||
* $interval is a single quoted strings rewritten by SQLiteQueryDriver::rewrite_query().
|
||||
* It is calculated in the private function deriveInterval().
|
||||
*
|
||||
* @param string $date representing the start date.
|
||||
* @param string $interval representing the expression of the time to add.
|
||||
* @return string date formated as '0000-00-00 00:00:00'.
|
||||
*/
|
||||
public function date_add($date, $interval) {
|
||||
$interval = $this->deriveInterval($interval);
|
||||
switch (strtolower($date)) {
|
||||
case "curdate()":
|
||||
$objDate = new Datetime($this->curdate());
|
||||
$objDate = new Datetime($this->curdate());
|
||||
$objDate->add(new DateInterval($interval));
|
||||
$returnval = $objDate->format("Y-m-d");
|
||||
break;
|
||||
case "now()":
|
||||
$objDate = new Datetime($this->now());
|
||||
$objDate = new Datetime($this->now());
|
||||
$objDate->add(new DateInterval($interval));
|
||||
$returnval = $objDate->format("Y-m-d H:i:s");
|
||||
break;
|
||||
default:
|
||||
$objDate = new Datetime($date);
|
||||
$objDate = new Datetime($date);
|
||||
$objDate->add(new DateInterval($interval));
|
||||
$returnval = $objDate->format("Y-m-d H:i:s");
|
||||
}
|
||||
return $returnval;
|
||||
}
|
||||
/**
|
||||
* Method to emulate MySQL DATE_SUB() function.
|
||||
*
|
||||
* This function substracts the time value of $interval expression from $date.
|
||||
* $interval is a single quoted strings rewritten by SQLiteQueryDriver::rewrite_query().
|
||||
* It is calculated in the private function deriveInterval().
|
||||
*
|
||||
* @param string $date representing the start date.
|
||||
* @param string $interval representing the expression of the time to substract.
|
||||
* @return string date formated as '0000-00-00 00:00:00'.
|
||||
*/
|
||||
public function date_sub($date, $interval) {
|
||||
$interval = $this->deriveInterval($interval);
|
||||
switch (strtolower($date)) {
|
||||
case "curdate()":
|
||||
$objDate = new Datetime($this->curdate());
|
||||
$objDate = new Datetime($this->curdate());
|
||||
$objDate->sub(new DateInterval($interval));
|
||||
$returnval = $objDate->format("Y-m-d");
|
||||
break;
|
||||
case "now()":
|
||||
$objDate = new Datetime($this->now());
|
||||
$objDate = new Datetime($this->now());
|
||||
$objDate->sub(new DateInterval($interval));
|
||||
$returnval = $objDate->format("Y-m-d H:i:s");
|
||||
break;
|
||||
default:
|
||||
$objDate = new Datetime($date);
|
||||
$objDate = new Datetime($date);
|
||||
$objDate->sub(new DateInterval($interval));
|
||||
$returnval = $objDate->format("Y-m-d H:i:s");
|
||||
}
|
||||
return $returnval;
|
||||
}
|
||||
/**
|
||||
* Method to calculate the interval time between two dates value.
|
||||
*
|
||||
* @access private
|
||||
* @param string $interval white space separated expression.
|
||||
* @return string representing the time to add or substract.
|
||||
*/
|
||||
private function deriveInterval($interval) {
|
||||
$interval = trim(substr(trim($interval), 8));
|
||||
$parts = explode(' ', $interval);
|
||||
|
@ -202,7 +358,7 @@ class PDOSQLiteUDFS {
|
|||
return 'P' . $days . 'D' . 'T' . $hours . 'H' . $minutes . 'M';
|
||||
break;
|
||||
case "day_hour":
|
||||
$days = intval($_parts[0]);
|
||||
$days = intval($_parts[0]);
|
||||
$hours = intval($_parts[1]);
|
||||
return 'P' . $days . 'D' . 'T' . $hours . 'H';
|
||||
break;
|
||||
|
@ -212,28 +368,63 @@ class PDOSQLiteUDFS {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to emulate MySQL DATE() function.
|
||||
*
|
||||
* @param string $date formatted as unix time.
|
||||
* @return string formatted as '0000-00-00'.
|
||||
*/
|
||||
public function date($date){
|
||||
return date("Y-m-d", strtotime($date));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to emulate MySQL ISNULL() function.
|
||||
*
|
||||
* This function returns true if the argument is null, and true if not.
|
||||
*
|
||||
* @param various types $field
|
||||
* @return boolean
|
||||
*/
|
||||
public function isnull($field){
|
||||
return is_null($field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to emulate MySQL IF() function.
|
||||
*
|
||||
* As 'IF' is a reserved word for PHP, function name must be changed.
|
||||
*
|
||||
* @param unknonw $expression the statement to be evaluated as true or false.
|
||||
* @param unknown $true statement or value returned if $expression is true.
|
||||
* @param unknown $false statement or value returned if $expression is false.
|
||||
* @return unknown
|
||||
*/
|
||||
public function _if($expression, $true, $false){
|
||||
return ($expression == true) ? $true : $false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to emulate MySQL REGEXP() function.
|
||||
*
|
||||
* @param string $field haystack
|
||||
* @param string $pattern: regular expression to match.
|
||||
* @return integer 1 if matched, 0 if not matched.
|
||||
*/
|
||||
public function regexp($field, $pattern){
|
||||
$pattern = str_replace('/', '\/', $pattern);
|
||||
$pattern = "/" . $pattern ."/i";
|
||||
return preg_match ($pattern, $field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to emulate MySQL CONCAT() function.
|
||||
*
|
||||
* SQLite does have CONCAT() function, but it has a different syntax from MySQL.
|
||||
* So this function must be manipulated here.
|
||||
*
|
||||
* @param string
|
||||
* @return NULL if the argument is null | string conatenated if the argument is given.
|
||||
*/
|
||||
public function concat() {
|
||||
$returnValue = "";
|
||||
$argsNum = func_num_args();
|
||||
$argsNum = func_num_args();
|
||||
$argsList = func_get_args();
|
||||
for ($i = 0; $i < $argsNum; $i++) {
|
||||
if (is_null($argsList[$i])) {
|
||||
|
@ -243,20 +434,51 @@ class PDOSQLiteUDFS {
|
|||
}
|
||||
return $returnValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to emulate MySQL FIELD() function.
|
||||
*
|
||||
* This function gets the list argument and compares the first item to all the others.
|
||||
* If the same value is found, it returns the position of that value. If not, it
|
||||
* returns 0.
|
||||
*
|
||||
* @param variable number of string, integer or double
|
||||
* @return unsigned integer
|
||||
*/
|
||||
public function field() {
|
||||
$numArgs = func_num_args();
|
||||
if ($numArgs < 2 or is_null(func_get_arg(0))) {
|
||||
return null;
|
||||
return 0;
|
||||
} else {
|
||||
$arg_list = func_get_args();
|
||||
}
|
||||
$arr = func_get_args();
|
||||
$searchString = strtolower(array_shift($arr));
|
||||
$searchString = array_shift($arg_list);
|
||||
for ($i = 0; $i < $numArgs-1; $i++) {
|
||||
if ($searchString === strtolower($arr[$i])) return $i + 1;
|
||||
if ($searchString === strtolower($arg_list[$i])) {
|
||||
return $i + 1;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to emulate MySQL LOG() function.
|
||||
*
|
||||
* Used with one argument, it returns the natural logarithm of X.
|
||||
* <code>
|
||||
* LOG(X)
|
||||
* </code>
|
||||
* Used with two arguments, it returns the natural logarithm of X base B.
|
||||
* <code>
|
||||
* LOG(B, X)
|
||||
* </code>
|
||||
* In this case, it returns the value of log(X) / log(B).
|
||||
*
|
||||
* Used without an argument, it returns false. This returned value will be
|
||||
* rewritten to 0, because SQLite doesn't understand true/false value.
|
||||
*
|
||||
* @param integer representing the base of the logarithm, which is optional.
|
||||
* @param double value to turn into logarithm.
|
||||
* @return double | NULL
|
||||
*/
|
||||
public function log() {
|
||||
$numArgs = func_num_args();
|
||||
if ($numArgs == 1) {
|
||||
|
@ -267,22 +489,36 @@ class PDOSQLiteUDFS {
|
|||
$arg2 = func_get_arg(1);
|
||||
return log($arg1)/log($arg2);
|
||||
} else {
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to emulate MySQL LEAST() function.
|
||||
*
|
||||
* This function rewrites the function name to SQLite compatible function name.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function least() {
|
||||
$arr = func_get_args();
|
||||
return min($arr);
|
||||
$arg_list = func_get_args();
|
||||
return "min($arg_list)";
|
||||
}
|
||||
|
||||
public function replace($haystack, $needle, $replace) {
|
||||
return str_replace($needle, $replace, $haystack);
|
||||
}
|
||||
|
||||
/**
|
||||
* These two functions are meaningless in SQLite
|
||||
* So we return meaningless statement and do nothing
|
||||
* Method to emulate MySQL GREATEST() function.
|
||||
*
|
||||
* This function rewrites the function name to SQLite compatible function name.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function greatest() {
|
||||
$arg_list = func_get_args();
|
||||
return "max($arg_list)";
|
||||
}
|
||||
/**
|
||||
* Method to dummy out MySQL GET_LOCK() function.
|
||||
*
|
||||
* This function is meaningless in SQLite, so we do nothing.
|
||||
*
|
||||
* @param string $name
|
||||
* @param integer $timeout
|
||||
* @return string
|
||||
|
@ -290,30 +526,61 @@ class PDOSQLiteUDFS {
|
|||
public function get_lock($name, $timeout) {
|
||||
return '1=1';
|
||||
}
|
||||
/**
|
||||
* Method to dummy out MySQL RELEASE_LOCK() function.
|
||||
*
|
||||
* This function is meaningless in SQLite, so we do nothing.
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
public function release_lock($name) {
|
||||
return '1=1';
|
||||
}
|
||||
|
||||
/**
|
||||
* MySQL aliases for upper and lower functions
|
||||
* @param $string
|
||||
* @return string
|
||||
* Method to emulate MySQL UCASE() function.
|
||||
*
|
||||
* This is MySQL alias for upper() function. This function rewrites it
|
||||
* to SQLite compatible name upper().
|
||||
*
|
||||
* @param string
|
||||
* @return string SQLite compatible function name.
|
||||
*/
|
||||
public function ucase($string) {
|
||||
return "upper($string)";
|
||||
}
|
||||
/**
|
||||
* Method to emulate MySQL LCASE() function.
|
||||
*
|
||||
*
|
||||
* This is MySQL alias for lower() function. This function rewrites it
|
||||
* to SQLite compatible name lower().
|
||||
*
|
||||
* @param string
|
||||
* @return string SQLite compatible function name.
|
||||
*/
|
||||
public function lcase($string) {
|
||||
return "lower($string)";
|
||||
}
|
||||
|
||||
/**
|
||||
* MySQL aliases for INET_NTOA and INET_ATON functions
|
||||
* @param unsigned integer, string respectively
|
||||
* @return string, unsigned integer respectively
|
||||
* Method to emulate MySQL INET_NTOA() function.
|
||||
*
|
||||
* This function gets 4 or 8 bytes integer and turn it into the network address.
|
||||
*
|
||||
* @param unsigned long integer
|
||||
* @return string
|
||||
*/
|
||||
public function inet_ntoa($num) {
|
||||
return long2ip($num);
|
||||
}
|
||||
/**
|
||||
* Method to emulate MySQL INET_ATON() function.
|
||||
*
|
||||
* This function gets the network address and turns it into integer.
|
||||
*
|
||||
* @param string
|
||||
* @return unsigned long integer
|
||||
*/
|
||||
public function inet_aton($addr) {
|
||||
$int_data = ip2long($addr);
|
||||
$unsigned_int_data = sprintf('%u', $address);
|
||||
|
@ -321,28 +588,41 @@ class PDOSQLiteUDFS {
|
|||
}
|
||||
|
||||
/**
|
||||
* MySQL aliase for DATEDIFF function
|
||||
* @param string, string
|
||||
* Method to emulate MySQL DATEDIFF() function.
|
||||
*
|
||||
* This function compares two dates value and returns the difference.
|
||||
*
|
||||
* PHP 5.3.2 has a serious bug in DateTime::diff(). So if users' PHP is that version,
|
||||
* we don't use that function. See https://bugs.php.net/bug.php?id=51184.
|
||||
*
|
||||
* @param string start
|
||||
* @param string end
|
||||
* @return string
|
||||
*/
|
||||
public function datediff($start, $end) {
|
||||
/* PHP 5.3.2 has a serious bug in DateTime::diff()
|
||||
* see https://bugs.php.net/bug.php?id=51184
|
||||
*/
|
||||
if (version_compare(PHP_VERSION, '5.3.2', '==')) {
|
||||
$start_date = strtotime($start);
|
||||
$end_date = strtotime($end);
|
||||
$interval = floor(($start_date - $end_date)/(3600*24));
|
||||
$interval = floor(($start_date - $end_date)/(3600*24));
|
||||
return $interval;
|
||||
} else {
|
||||
$start_date = new DateTime($start);
|
||||
$end_date = new DateTime($end);
|
||||
$interval = $end_date->diff($start_date, false);
|
||||
$end_date = new DateTime($end);
|
||||
$interval = $end_date->diff($start_date, false);
|
||||
return $interval->format('%r%a');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* emulates MySQL LOCATE() function
|
||||
* Method to emulate MySQL LOCATE() function.
|
||||
*
|
||||
* This function returns the position if $substr is found in $str. If not,
|
||||
* it returns 0. If mbstring extension is loaded, mb_strpos() function is
|
||||
* used.
|
||||
*
|
||||
* @param string needle
|
||||
* @param string haystack
|
||||
* @param integer position
|
||||
* @return integer
|
||||
*/
|
||||
public function locate($substr, $str, $pos = 0) {
|
||||
if (!extension_loaded('mbstring')) {
|
||||
|
@ -360,7 +640,13 @@ class PDOSQLiteUDFS {
|
|||
}
|
||||
}
|
||||
/**
|
||||
* Method to return MySQL version.
|
||||
*
|
||||
* This function only returns WordPress $required_mysql_version, because it is
|
||||
* meaningless for SQLite database.
|
||||
*
|
||||
* @param none
|
||||
* @return string representing the version number
|
||||
*/
|
||||
public function version() {
|
||||
global $required_mysql_version;
|
||||
|
|
|
@ -1,17 +1,20 @@
|
|||
<?php
|
||||
/**
|
||||
* This file contains the only one function wp_install().
|
||||
*
|
||||
* @package SQLite Integration
|
||||
* @author Kojima Toshiyasu, Justin Adie
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This function overrides wp_install() in wp-admin/includes/upgrade.php
|
||||
*/
|
||||
if (!defined('ABSPATH')) {
|
||||
echo 'Thank you, but you are not allowed to access this file.';
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* This function overrides wp_install() in wp-admin/includes/upgrade.php
|
||||
*/
|
||||
function wp_install($blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '') {
|
||||
if (!empty($deprecated))
|
||||
_deprecated_argument(__FUNCTION__, '2.6');
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
/*
|
||||
* script for SQLite Integration
|
||||
* this file is only included on the documentation page and the utilities page
|
||||
/**
|
||||
* This is a part of SQLite Integration.
|
||||
*
|
||||
* This script is only included on the documentation and utility page.
|
||||
*
|
||||
* @author Kojima Toshiyasu
|
||||
*/
|
||||
jQuery(document).ready(function($) {
|
||||
var $table = null;
|
||||
|
|
|
@ -156,12 +156,12 @@ msgid ""
|
|||
"SQLite for its database. But PDO for WordPress doesn't seem to be maintained "
|
||||
"any more only to be outdated. SQLite Integration makes use of the basic "
|
||||
"ideas and framework of PDO for WordPress, adds some new features and updates "
|
||||
"it to be able to work with the newest version of WordPress(3.8)."
|
||||
"it to be able to work with the newest version of WordPress(3.8.1)."
|
||||
msgstr ""
|
||||
"このプラグインは<a href=\"http://wordpress.org/extend/plugins/pdo-for-wordpress/\">"
|
||||
"PDO for WordPress</a>の後継です。PDO for WordPressはWordPressでSQLiteを使えるようにする"
|
||||
"ものでしたが、もうメンテナンスされていないようで、古くなってしまいました。SQLite Integrationは、その基本的な"
|
||||
"考えと枠組みを使って、新たな機能を追加し、最新のWordPress(3.8)で動作するように"
|
||||
"考えと枠組みを使って、新たな機能を追加し、最新のWordPress(3.8.1)で動作するように"
|
||||
"したものです。"
|
||||
|
||||
#: utilities/documentation.php:43
|
||||
|
@ -243,7 +243,7 @@ msgstr ""
|
|||
"が扱えないものもあります。だから..."
|
||||
|
||||
#: utilities/documentation.php:68
|
||||
msgid "There are some plugins that you can't use in any way.<br />"
|
||||
msgid "There are some plugins that you can't use. No way around.<br />"
|
||||
msgstr "どうしても使えないプラグインがあります。"
|
||||
|
||||
#: utilities/documentation.php:69
|
||||
|
@ -266,7 +266,7 @@ msgstr ""
|
|||
msgid ""
|
||||
"Some plugins do work fine if you rewrite MySQL functions. I made some patch "
|
||||
"files and <a href=\"%s?page=patch\">Patch Utility</a>. See also the <a href="
|
||||
"\"http://dogwood.skr.jp/wordpress/sqlite-integration\">Plugin Page</a> for "
|
||||
"\"http://dogwood.skr.jp/wordpress/sqlite-integration\">SQLite Integration page</a> for "
|
||||
"more details."
|
||||
msgstr ""
|
||||
"MySQLの関数を書き換えると動作するプラグインがあります。いくつかはパッチファイルと、<a href=\"%s?page=patch\">"
|
||||
|
@ -349,9 +349,7 @@ msgstr ""
|
|||
#: utilities/documentation.php:104
|
||||
#, php-format
|
||||
msgid ""
|
||||
"Most of the plugins will work fine with this plugin. But there are some that "
|
||||
"you need to rewrite some codes in them, and there are others that you can't "
|
||||
"use with this plugin. This is the list of the problematic plugins (far from "
|
||||
"This is the list of the problematic plugins (far from "
|
||||
"complete). You can see informations about your installed plugins in the <a "
|
||||
"href=\"%s?page=sys-info\">System Info</a> page. To see more details, please "
|
||||
"visit the <a href=\"http://dogwood.skr.jp/wordpress/sqlite-integration"
|
||||
|