-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathdb.php
More file actions
4935 lines (4625 loc) · 179 KB
/
db.php
File metadata and controls
4935 lines (4625 loc) · 179 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Plugin Name: WP SQLite DB
* Description: SQLite database driver drop-in. (based on SQLite Integration by Kojima Toshiyasu)
* Author: Evan Mattson
* Author URI: https://aaemnnost.tv
* Plugin URI: https://github.com/aaemnnosttv/wp-sqlite-db
* Version: 1.3.3
* Requires PHP: 5.6
*
* This file must be placed in wp-content/db.php.
* WordPress loads this file automatically.
*
* This project is based on the original work of Kojima Toshiyasu and his SQLite Integration plugin.
*/
namespace WP_SQLite_DB {
use DateTime;
use DateInterval;
use PDO;
use PDOException;
use SQLite3;
if (! defined('ABSPATH')) {
exit;
}
/**
* 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 you want to use SQLite, the line below will do. Or simply removing the line will
* be enough.
*
* <code>
* define('USE_MYSQL', false);
* </code>
*/
if (defined('USE_MYSQL') && USE_MYSQL) {
return;
}
function pdo_log_error($message, $data = null)
{
if (strpos($_SERVER['SCRIPT_NAME'], 'wp-admin') !== false) {
$admin_dir = '';
} else {
$admin_dir = 'wp-admin/';
}
die(<<<HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>WordPress › Error</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<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>
<p>$message</p>
<p>$data</p>
</body>
<html>
HTML
);
}
if (version_compare(PHP_VERSION, '5.4', '<')) {
pdo_log_error('PHP version on this server is too old.', sprintf("Your server is running PHP version %d but this SQLite driver requires at least 5.4", phpversion()));
}
if (! extension_loaded('pdo')) {
pdo_log_error('PHP PDO Extension is not loaded.',
'Your PHP installation appears to be missing the PDO extension which is required for this version of WordPress.');
}
if (! extension_loaded('pdo_sqlite')) {
pdo_log_error('PDO Driver for SQLite is missing.',
'Your PHP installation 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');
*/
/**
* 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 . '/');
} else {
define('FQDBDIR', DB_DIR);
}
} else {
if (defined('WP_CONTENT_DIR')) {
define('FQDBDIR', WP_CONTENT_DIR . '/database/');
} else {
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');
}
/**
* 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 PDO $pdo
*/
public function __construct($pdo)
{
if (! $pdo) {
wp_die('Database is not initialized.', 'Database Error');
}
foreach ($this->functions as $f => $t) {
if (PHP_VERSION_ID >= 80400) {
$pdo->createFunction($f, [$this, $t]);
} else {
$pdo->sqliteCreateFunction($f, [$this, $t]);
}
}
}
/**
* array to define MySQL function => function defined with PHP.
*
* Replaced functions must be public.
*
* @var array
*/
private $functions = [
'month' => 'month',
'year' => 'year',
'day' => 'day',
'unix_timestamp' => 'unix_timestamp',
'now' => 'now',
'char_length' => 'char_length',
'md5' => 'md5',
'curdate' => 'curdate',
'rand' => 'rand',
'substring' => 'substring',
'dayofmonth' => 'day',
'second' => 'second',
'minute' => 'minute',
'hour' => 'hour',
'date_format' => 'dateformat',
'from_unixtime' => 'from_unixtime',
'date_add' => 'date_add',
'date_sub' => 'date_sub',
'adddate' => 'date_add',
'subdate' => 'date_sub',
'localtime' => 'now',
'localtimestamp' => 'now',
'isnull' => 'isnull',
'if' => '_if',
'regexpp' => 'regexp',
'concat' => 'concat',
'field' => 'field',
'log' => 'log',
'least' => 'least',
'greatest' => 'greatest',
'get_lock' => 'get_lock',
'release_lock' => 'release_lock',
'ucase' => 'ucase',
'lcase' => 'lcase',
'inet_ntoa' => 'inet_ntoa',
'inet_aton' => 'inet_aton',
'datediff' => 'datediff',
'locate' => 'locate',
'utc_date' => 'utc_date',
'utc_time' => 'utc_time',
'utc_timestamp' => 'utc_timestamp',
'version' => 'version',
];
/**
* Method to extract the month value from the date.
*
* @param string representing the date formatted 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 formatted 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 formatted 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 formatted 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 formatted 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 formatted 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 formatted as '00:00:00'.
*
* @return number
*/
public function hour($time)
{
list($hours) = 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)
{
//convert to ISO time
$date = date("Y-m-d H:i:s", $field);
return is_null($format) ? $date : $this->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 int 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 int
*/
public function rand()
{
return mt_rand(0, 1);
}
/**
* Method to emulate MySQL SUBSTRING() function.
*
* This function rewrites the function name to SQLite compatible substr(),
* which can manipulate UTF-8 characters.
*
* @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)
{
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_date_formats = [
'%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);
$format = strtr($format, $mysql_php_date_formats);
$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 formatted as '0000-00-00 00:00:00'.
* @throws Exception
*/
public function date_add($date, $interval)
{
$interval = $this->deriveInterval($interval);
switch (strtolower($date)) {
case "curdate()":
$objDate = new DateTime($this->curdate());
$objDate->add(new DateInterval($interval));
$formatted = $objDate->format("Y-m-d");
break;
case "now()":
$objDate = new DateTime($this->now());
$objDate->add(new DateInterval($interval));
$formatted = $objDate->format("Y-m-d H:i:s");
break;
default:
$objDate = new DateTime($date);
$objDate->add(new DateInterval($interval));
$formatted = $objDate->format("Y-m-d H:i:s");
}
return $formatted;
}
/**
* Method to emulate MySQL DATE_SUB() function.
*
* This function subtracts 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 subtract.
*
* @return string date formatted as '0000-00-00 00:00:00'.
* @throws Exception
*/
public function date_sub($date, $interval)
{
$interval = $this->deriveInterval($interval);
switch (strtolower($date)) {
case "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->sub(new DateInterval($interval));
$returnval = $objDate->format("Y-m-d H:i:s");
break;
default:
$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);
foreach ($parts as $part) {
if (! empty($part)) {
$_parts[] = $part;
}
}
$type = strtolower(end($_parts));
switch ($type) {
case "second":
$unit = 'S';
return 'PT' . $_parts[0] . $unit;
break;
case "minute":
$unit = 'M';
return 'PT' . $_parts[0] . $unit;
break;
case "hour":
$unit = 'H';
return 'PT' . $_parts[0] . $unit;
break;
case "day":
$unit = 'D';
return 'P' . $_parts[0] . $unit;
break;
case "week":
$unit = 'W';
return 'P' . $_parts[0] . $unit;
break;
case "month":
$unit = 'M';
return 'P' . $_parts[0] . $unit;
break;
case "year":
$unit = 'Y';
return 'P' . $_parts[0] . $unit;
break;
case "minute_second":
list($minutes, $seconds) = explode(':', $_parts[0]);
return 'PT' . $minutes . 'M' . $seconds . 'S';
case "hour_second":
list($hours, $minutes, $seconds) = explode(':', $_parts[0]);
return 'PT' . $hours . 'H' . $minutes . 'M' . $seconds . 'S';
case "hour_minute":
list($hours, $minutes) = explode(':', $_parts[0]);
return 'PT' . $hours . 'H' . $minutes . 'M';
case "day_second":
$days = intval($_parts[0]);
list($hours, $minutes, $seconds) = explode(':', $_parts[1]);
return 'P' . $days . 'D' . 'T' . $hours . 'H' . $minutes . 'M' . $seconds . 'S';
case "day_minute":
$days = intval($_parts[0]);
list($hours, $minutes) = explode(':', $parts[1]);
return 'P' . $days . 'D' . 'T' . $hours . 'H' . $minutes . 'M';
case "day_hour":
$days = intval($_parts[0]);
$hours = intval($_parts[1]);
return 'P' . $days . 'D' . 'T' . $hours . 'H';
case "year_month":
list($years, $months) = explode('-', $_parts[0]);
return 'P' . $years . 'Y' . $months . 'M';
}
}
/**
* 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();
$argsList = func_get_args();
for ($i = 0; $i < $argsNum; $i++) {
if (is_null($argsList[$i])) {
return null;
}
$returnValue .= $argsList[$i];
}
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 int...|float... variable number of string, integer or double
*
* @return int unsigned integer
*/
public function field()
{
global $wpdb;
$numArgs = func_num_args();
if ($numArgs < 2 or is_null(func_get_arg(0))) {
return 0;
} else {
$arg_list = func_get_args();
}
$searchString = array_shift($arg_list);
$str_to_check = substr($searchString, 0, strpos($searchString, '.'));
$str_to_check = str_replace($wpdb->prefix, '', $str_to_check);
if ($str_to_check && in_array(trim($str_to_check), $wpdb->tables)) {
return 0;
}
for ($i = 0; $i < $numArgs - 1; $i++) {
if ($searchString === strtolower($arg_list[$i])) {
return $i + 1;
}
}
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) {
$arg1 = func_get_arg(0);
return log($arg1);
} elseif ($numArgs == 2) {
$arg1 = func_get_arg(0);
$arg2 = func_get_arg(1);
return log($arg1) / log($arg2);
} else {
return null;
}
}
/**
* 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
*/
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';
}
/**
* 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)";
}
/**
* 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 int long integer
*/
public function inet_aton($addr)
{
return absint(ip2long($addr));
}
/**
* Method to emulate MySQL DATEDIFF() function.
*
* This function compares two dates value and returns the difference.
*
* @param string start
* @param string end
*
* @return string
*/
public function datediff($start, $end)
{
$start_date = new DateTime($start);
$end_date = new DateTime($end);
$interval = $end_date->diff($start_date, false);
return $interval->format('%r%a');
}
/**
* 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')) {
if (($val = strpos($str, $substr, $pos)) !== false) {
return $val + 1;
} else {
return 0;
}
} else {
if (($val = mb_strpos($str, $substr, $pos)) !== false) {
return $val + 1;
} else {
return 0;
}
}
}
/**
* Method to return GMT date in the string format.
*
* @param none
*
* @return string formatted GMT date 'dddd-mm-dd'
*/
public function utc_date()
{
return gmdate('Y-m-d', time());
}
/**
* Method to return GMT time in the string format.
*
* @param none
*
* @return string formatted GMT time '00:00:00'
*/
public function utc_time()
{
return gmdate('H:i:s', time());
}
/**
* Method to return GMT time stamp in the string format.
*
* @param none
*
* @return string formatted GMT timestamp 'yyyy-mm-dd 00:00:00'
*/
public function utc_timestamp()
{
return gmdate('Y-m-d H:i:s', time());
}
/**
* Method to return MySQL version.
*
* This function only returns the current newest version number of MySQL,
* because it is meaningless for SQLite database.
*
* @param none
*
* @return string representing the version number: major_version.minor_version
*/
public function version()
{
//global $required_mysql_version;
//return $required_mysql_version;
return '5.5';
}
}
/**
* This class extends PDO class and does the real work.
*
* It accepts a request from wpdb class, initialize PDO instance,
* execute SQL statement, and returns the results to WordPress.
*/
class PDOEngine extends PDO