Skip to content

Commit 0976dca

Browse files
committed
Update
1 parent 6e6fe59 commit 0976dca

File tree

11 files changed

+110
-74
lines changed

11 files changed

+110
-74
lines changed

dist/SuperSQL.php

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
License: MIT (https://github.com/ThreeLetters/SuperSQL/blob/master/LICENSE)
55
Source: https://github.com/ThreeLetters/SQL-Library
66
Build: v1.0.2
7-
Built on: 10/08/2017
7+
Built on: 11/08/2017
88
*/
99

1010
// lib/connector/index.php
@@ -45,6 +45,13 @@ function init(&$data, &$mode) {
4545
$this->result = array();
4646
}
4747
}
48+
function close() {
49+
$this->complete = true;
50+
if ($this->stmt) {
51+
$this->stmt->closeCursor();
52+
$this->stmt = null;
53+
}
54+
}
4855
function fetchNextRow() {
4956
$row = $this->stmt->fetch();
5057
if ($row) {
@@ -276,7 +283,7 @@ class AdvParser
276283
{
277284
static function getArg(&$str)
278285
{
279-
if (substr($str, 0, 1) === '[' && substr($str, 3, 1) === ']') {
286+
if ($str[0] === '[' && substr($str, 3, 1) === ']') {
280287
$out = substr($str, 1, 2);
281288
$str = substr($str, 4);
282289
return $out;
@@ -306,7 +313,7 @@ function stripArgs(&$key)
306313
$b = strrpos($key, ']', -1);
307314
if ($b !== false)
308315
$key = substr($key, $b + 1);
309-
if (substr($key, 0, 1) === '#') {
316+
if ($key[0] === '#') {
310317
$key = substr($key, 1);
311318
}
312319
}
@@ -407,23 +414,21 @@ static function table($table)
407414
}
408415
static function value($type, $value)
409416
{
410-
$var = strtolower($type);
411-
if (!$var)
412-
$var = strtolower(gettype($value));
417+
$var = $type ? $type : gettype($value);
413418
$type = \PDO::PARAM_STR;
414419
$dtype = 2;
415420
if ($var === 'integer' || $var === 'int' || $var === 'double' || $var === 'doub') {
421+
$type = \PDO::PARAM_INT;
416422
$dtype = 1;
417423
$value = (int) $value;
418424
} else if ($var === 'string' || $var === 'str') {
419-
$type = \PDO::PARAM_STR;
420425
$value = (string) $value;
421426
$dtype = 2;
422427
} else if ($var === 'boolean' || $var === 'bool') {
423428
$type = \PDO::PARAM_BOOL;
424429
$value = $value ? '1' : '0';
425430
$dtype = 0;
426-
} else if ($var === 'null') {
431+
} else if ($var === 'null' || $var === 'NULL') {
427432
$dtype = 4;
428433
$type = \PDO::PARAM_NULL;
429434
$value = null;
@@ -432,11 +437,9 @@ static function value($type, $value)
432437
$dtype = 3;
433438
} else if ($var === 'json') {
434439
$dtype = 5;
435-
$type = \PDO::PARAM_STR;
436440
$value = json_encode($value);
437441
} else if ($var === 'obj') {
438442
$dtype = 6;
439-
$type = \PDO::PARAM_STR;
440443
$value = serialize($value);
441444
} else {
442445
$value = (string)$value;
@@ -450,7 +453,8 @@ static function value($type, $value)
450453
}
451454
static function getType(&$str)
452455
{
453-
if (substr($str, -1) === ']') {
456+
$len = strlen($str);
457+
if ($str[$len - 1] === ']') {
454458
$start = strrpos($str, '[');
455459
if ($start === false) {
456460
return '';
@@ -464,9 +468,9 @@ static function getType(&$str)
464468
static function rmComments($str) {
465469
$i = strpos($str,'#');
466470
if ($i !== false) {
467-
$str = substr($str,0,$i);
471+
$str = trim(substr($str,0,$i));
468472
}
469-
return trim($str);
473+
return $str;
470474
}
471475
static function conditions($dt, &$values = false, &$map = false, &$index = 0)
472476
{
@@ -475,7 +479,7 @@ static function conditions($dt, &$values = false, &$map = false, &$index = 0)
475479
$num = 0;
476480
$sql = '';
477481
foreach ($dt as $key => &$val) {
478-
if (substr($key, 0, 1) === '#') {
482+
if ($key[0] === '#') {
479483
$raw = true;
480484
$key = substr($key, 1);
481485
} else {
@@ -583,7 +587,7 @@ static function conditions($dt, &$values = false, &$map = false, &$index = 0)
583587
}
584588
static function JOIN($join, &$sql) {
585589
foreach ($join as $key => &$val) {
586-
if (substr($key, 0, 1) === '#') {
590+
if ($key[0] === '#') {
587591
$raw = true;
588592
$key = substr($key, 1);
589593
} else {
@@ -635,7 +639,7 @@ static function SELECT($table, $columns, $where, $join, $limit)
635639
$into = ' ' . $columns[0] . ' ';
636640
}
637641
if ($len > $req) {
638-
for ($i = $req; $i < $len; $i++) {
642+
for ($i = $req; isset($columns[$i]); $i++) {
639643
$b = self::getType($columns[$i]);
640644
$t = $b ? self::getType($columns[$i]) : false;
641645
if (!$t && $b) {
@@ -703,7 +707,7 @@ static function INSERT($table, $data)
703707
$multi = isset($data[0]);
704708
$dt = $multi ? $data[0] : $data;
705709
foreach ($dt as $key => &$val) {
706-
if (substr($key, 0, 1) === '#') {
710+
if ($key[0] === '#') {
707711
$raw = true;
708712
$key = substr($key, 1);
709713
} else {
@@ -748,7 +752,7 @@ static function UPDATE($table, $data, $where)
748752
$multi = isset($data[0]);
749753
$dt = $multi ? $data[0] : $data;
750754
foreach ($dt as $key => &$val) {
751-
if (substr($key, 0, 1) === '#') {
755+
if ($key[0] === '#') {
752756
$raw = true;
753757
$key = substr($key, 1);
754758
} else {

dist/SuperSQL_advanced.php

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
License: MIT (https://github.com/ThreeLetters/SuperSQL/blob/master/LICENSE)
55
Source: https://github.com/ThreeLetters/SQL-Library
66
Build: v1.0.2
7-
Built on: 10/08/2017
7+
Built on: 11/08/2017
88
*/
99

1010
// lib/connector/index.php
@@ -45,6 +45,13 @@ function init(&$data, &$mode) {
4545
$this->result = array();
4646
}
4747
}
48+
function close() {
49+
$this->complete = true;
50+
if ($this->stmt) {
51+
$this->stmt->closeCursor();
52+
$this->stmt = null;
53+
}
54+
}
4855
function fetchNextRow() {
4956
$row = $this->stmt->fetch();
5057
if ($row) {
@@ -182,7 +189,7 @@ class AdvParser
182189
{
183190
static function getArg(&$str)
184191
{
185-
if (substr($str, 0, 1) === '[' && substr($str, 3, 1) === ']') {
192+
if ($str[0] === '[' && substr($str, 3, 1) === ']') {
186193
$out = substr($str, 1, 2);
187194
$str = substr($str, 4);
188195
return $out;
@@ -212,7 +219,7 @@ function stripArgs(&$key)
212219
$b = strrpos($key, ']', -1);
213220
if ($b !== false)
214221
$key = substr($key, $b + 1);
215-
if (substr($key, 0, 1) === '#') {
222+
if ($key[0] === '#') {
216223
$key = substr($key, 1);
217224
}
218225
}
@@ -313,23 +320,21 @@ static function table($table)
313320
}
314321
static function value($type, $value)
315322
{
316-
$var = strtolower($type);
317-
if (!$var)
318-
$var = strtolower(gettype($value));
323+
$var = $type ? $type : gettype($value);
319324
$type = \PDO::PARAM_STR;
320325
$dtype = 2;
321326
if ($var === 'integer' || $var === 'int' || $var === 'double' || $var === 'doub') {
327+
$type = \PDO::PARAM_INT;
322328
$dtype = 1;
323329
$value = (int) $value;
324330
} else if ($var === 'string' || $var === 'str') {
325-
$type = \PDO::PARAM_STR;
326331
$value = (string) $value;
327332
$dtype = 2;
328333
} else if ($var === 'boolean' || $var === 'bool') {
329334
$type = \PDO::PARAM_BOOL;
330335
$value = $value ? '1' : '0';
331336
$dtype = 0;
332-
} else if ($var === 'null') {
337+
} else if ($var === 'null' || $var === 'NULL') {
333338
$dtype = 4;
334339
$type = \PDO::PARAM_NULL;
335340
$value = null;
@@ -338,11 +343,9 @@ static function value($type, $value)
338343
$dtype = 3;
339344
} else if ($var === 'json') {
340345
$dtype = 5;
341-
$type = \PDO::PARAM_STR;
342346
$value = json_encode($value);
343347
} else if ($var === 'obj') {
344348
$dtype = 6;
345-
$type = \PDO::PARAM_STR;
346349
$value = serialize($value);
347350
} else {
348351
$value = (string)$value;
@@ -356,7 +359,8 @@ static function value($type, $value)
356359
}
357360
static function getType(&$str)
358361
{
359-
if (substr($str, -1) === ']') {
362+
$len = strlen($str);
363+
if ($str[$len - 1] === ']') {
360364
$start = strrpos($str, '[');
361365
if ($start === false) {
362366
return '';
@@ -370,9 +374,9 @@ static function getType(&$str)
370374
static function rmComments($str) {
371375
$i = strpos($str,'#');
372376
if ($i !== false) {
373-
$str = substr($str,0,$i);
377+
$str = trim(substr($str,0,$i));
374378
}
375-
return trim($str);
379+
return $str;
376380
}
377381
static function conditions($dt, &$values = false, &$map = false, &$index = 0)
378382
{
@@ -381,7 +385,7 @@ static function conditions($dt, &$values = false, &$map = false, &$index = 0)
381385
$num = 0;
382386
$sql = '';
383387
foreach ($dt as $key => &$val) {
384-
if (substr($key, 0, 1) === '#') {
388+
if ($key[0] === '#') {
385389
$raw = true;
386390
$key = substr($key, 1);
387391
} else {
@@ -489,7 +493,7 @@ static function conditions($dt, &$values = false, &$map = false, &$index = 0)
489493
}
490494
static function JOIN($join, &$sql) {
491495
foreach ($join as $key => &$val) {
492-
if (substr($key, 0, 1) === '#') {
496+
if ($key[0] === '#') {
493497
$raw = true;
494498
$key = substr($key, 1);
495499
} else {
@@ -541,7 +545,7 @@ static function SELECT($table, $columns, $where, $join, $limit)
541545
$into = ' ' . $columns[0] . ' ';
542546
}
543547
if ($len > $req) {
544-
for ($i = $req; $i < $len; $i++) {
548+
for ($i = $req; isset($columns[$i]); $i++) {
545549
$b = self::getType($columns[$i]);
546550
$t = $b ? self::getType($columns[$i]) : false;
547551
if (!$t && $b) {
@@ -609,7 +613,7 @@ static function INSERT($table, $data)
609613
$multi = isset($data[0]);
610614
$dt = $multi ? $data[0] : $data;
611615
foreach ($dt as $key => &$val) {
612-
if (substr($key, 0, 1) === '#') {
616+
if ($key[0] === '#') {
613617
$raw = true;
614618
$key = substr($key, 1);
615619
} else {
@@ -654,7 +658,7 @@ static function UPDATE($table, $data, $where)
654658
$multi = isset($data[0]);
655659
$dt = $multi ? $data[0] : $data;
656660
foreach ($dt as $key => &$val) {
657-
if (substr($key, 0, 1) === '#') {
661+
if ($key[0] === '#') {
658662
$raw = true;
659663
$key = substr($key, 1);
660664
} else {

0 commit comments

Comments
 (0)