Skip to content

Commit bf23579

Browse files
committed
Merge pull request #332 from avbdr/master
fixes
2 parents e0153d7 + 12c0a1d commit bf23579

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed

MysqliDb.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ public function rawQueryValue ($query, $bindParams = null) {
396396
*/
397397
public function query($query, $numRows = null)
398398
{
399-
$this->_query = filter_var($query, FILTER_SANITIZE_STRING);
399+
$this->_query = $query;
400400
$stmt = $this->_buildQuery($numRows);
401401
$stmt->execute();
402402
$this->_stmtError = $stmt->error;
@@ -694,7 +694,7 @@ public function join($joinTable, $joinCondition, $joinType = '')
694694
die ('Wrong JOIN type: '.$joinType);
695695

696696
if (!is_object ($joinTable))
697-
$joinTable = self::$prefix . filter_var($joinTable, FILTER_SANITIZE_STRING);
697+
$joinTable = self::$prefix . $joinTable;
698698

699699
$this->_join[] = Array ($joinType, $joinTable, $joinCondition);
700700

dbObject.php

+22-15
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
* @version 2.2
1212
*
1313
* @method int count ()
14+
* @method dbObject ArrayBuilder()
15+
* @method dbObject JsonBuilder()
16+
* @method dbObject ObjectBuilder()
1417
* @method mixed byId (string $id, mixed $fields)
1518
* @method mixed get (mixed $limit, mixed $fields)
1619
* @method mixed getOne (mixed $fields)
@@ -181,21 +184,19 @@ public function __unset ($name) {
181184
*
182185
* @return dbObject
183186
*/
184-
public static function JsonBuilder () {
185-
$obj = new static;
186-
$obj->returnType = 'Json';
187-
return $obj;
187+
private function JsonBuilder () {
188+
$this->returnType = 'Json';
189+
return $return;
188190
}
189191

190192
/**
191193
* Helper function to create dbObject with Array return type
192194
*
193195
* @return dbObject
194196
*/
195-
public static function ArrayBuilder () {
196-
$obj = new static;
197-
$obj->returnType = 'Array';
198-
return $obj;
197+
private function ArrayBuilder () {
198+
$this->returnType = 'Array';
199+
return $this;
199200
}
200201

201202
/**
@@ -204,8 +205,9 @@ public static function ArrayBuilder () {
204205
*
205206
* @return dbObject
206207
*/
207-
public static function ObjectBuilder () {
208-
return new static;
208+
private function ObjectBuilder () {
209+
$this->returnType = 'Object';
210+
return $this;
209211
}
210212

211213
/**
@@ -297,7 +299,7 @@ public function delete () {
297299
*
298300
* @return dbObject|array
299301
*/
300-
private function byId ($id, $fields = null) {
302+
protected function byId ($id, $fields = null) {
301303
$this->db->where (MysqliDb::$prefix . $this->dbTable . '.' . $this->primaryKey, $id);
302304
return $this->getOne ($fields);
303305
}
@@ -310,7 +312,7 @@ private function byId ($id, $fields = null) {
310312
*
311313
* @return dbObject
312314
*/
313-
private function getOne ($fields = null) {
315+
protected function getOne ($fields = null) {
314316
$this->processHasOneWith ();
315317
$results = $this->db->ArrayBuilder()->getOne ($this->dbTable, $fields);
316318
if ($this->db->count == 0)
@@ -340,7 +342,7 @@ private function getOne ($fields = null) {
340342
*
341343
* @return array Array of dbObjects
342344
*/
343-
private function get ($limit = null, $fields = null) {
345+
protected function get ($limit = null, $fields = null) {
344346
$objects = Array ();
345347
$this->processHasOneWith ();
346348
$results = $this->db->ArrayBuilder()->get ($this->dbTable, $limit, $fields);
@@ -409,9 +411,11 @@ private function join ($objectName, $key = null, $joinType = 'LEFT') {
409411
*
410412
* @return int
411413
*/
412-
private function count () {
414+
protected function count () {
413415
$res = $this->db->ArrayBuilder()->getValue ($this->dbTable, "count(*)");
414-
return $res['cnt'];
416+
if (!$res)
417+
return 0;
418+
return $res;
415419
}
416420

417421
/**
@@ -608,6 +612,9 @@ private function validate ($data) {
608612
case "int":
609613
$regexp = "/^[0-9]*$/";
610614
break;
615+
case "double":
616+
$regexp = "/^[0-9\.]*$/";
617+
break;
611618
case "bool":
612619
$regexp = '/^[yes|no|0|1|true|false]$/i';
613620
break;

tests/dbObjectTests.php

+6
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ function createTable ($name, $data) {
141141
exit;
142142
}
143143

144+
$products = product::with('userId')->ArrayBuilder()->get(2);
145+
if (!is_array ($products[0]['userId']) || !is_array ($products[1]['userId'])) {
146+
echo "Error in with processing in get";
147+
exit;
148+
}
149+
144150
$depts = product::join('user')->orderBy('`products`.id', 'desc')->get(5);
145151
foreach ($depts as $d) {
146152
if (!is_object($d)) {

0 commit comments

Comments
 (0)