Commit bf235793 authored by Alexander Butenko's avatar Alexander Butenko

Merge pull request #332 from avbdr/master

fixes
parents e0153d7f 12c0a1db
...@@ -396,7 +396,7 @@ class MysqliDb ...@@ -396,7 +396,7 @@ class MysqliDb
*/ */
public function query($query, $numRows = null) public function query($query, $numRows = null)
{ {
$this->_query = filter_var($query, FILTER_SANITIZE_STRING); $this->_query = $query;
$stmt = $this->_buildQuery($numRows); $stmt = $this->_buildQuery($numRows);
$stmt->execute(); $stmt->execute();
$this->_stmtError = $stmt->error; $this->_stmtError = $stmt->error;
...@@ -694,7 +694,7 @@ class MysqliDb ...@@ -694,7 +694,7 @@ class MysqliDb
die ('Wrong JOIN type: '.$joinType); die ('Wrong JOIN type: '.$joinType);
if (!is_object ($joinTable)) if (!is_object ($joinTable))
$joinTable = self::$prefix . filter_var($joinTable, FILTER_SANITIZE_STRING); $joinTable = self::$prefix . $joinTable;
$this->_join[] = Array ($joinType, $joinTable, $joinCondition); $this->_join[] = Array ($joinType, $joinTable, $joinCondition);
......
...@@ -11,6 +11,9 @@ ...@@ -11,6 +11,9 @@
* @version 2.2 * @version 2.2
* *
* @method int count () * @method int count ()
* @method dbObject ArrayBuilder()
* @method dbObject JsonBuilder()
* @method dbObject ObjectBuilder()
* @method mixed byId (string $id, mixed $fields) * @method mixed byId (string $id, mixed $fields)
* @method mixed get (mixed $limit, mixed $fields) * @method mixed get (mixed $limit, mixed $fields)
* @method mixed getOne (mixed $fields) * @method mixed getOne (mixed $fields)
...@@ -181,10 +184,9 @@ class dbObject { ...@@ -181,10 +184,9 @@ class dbObject {
* *
* @return dbObject * @return dbObject
*/ */
public static function JsonBuilder () { private function JsonBuilder () {
$obj = new static; $this->returnType = 'Json';
$obj->returnType = 'Json'; return $return;
return $obj;
} }
/** /**
...@@ -192,10 +194,9 @@ class dbObject { ...@@ -192,10 +194,9 @@ class dbObject {
* *
* @return dbObject * @return dbObject
*/ */
public static function ArrayBuilder () { private function ArrayBuilder () {
$obj = new static; $this->returnType = 'Array';
$obj->returnType = 'Array'; return $this;
return $obj;
} }
/** /**
...@@ -204,8 +205,9 @@ class dbObject { ...@@ -204,8 +205,9 @@ class dbObject {
* *
* @return dbObject * @return dbObject
*/ */
public static function ObjectBuilder () { private function ObjectBuilder () {
return new static; $this->returnType = 'Object';
return $this;
} }
/** /**
...@@ -297,7 +299,7 @@ class dbObject { ...@@ -297,7 +299,7 @@ class dbObject {
* *
* @return dbObject|array * @return dbObject|array
*/ */
private function byId ($id, $fields = null) { protected function byId ($id, $fields = null) {
$this->db->where (MysqliDb::$prefix . $this->dbTable . '.' . $this->primaryKey, $id); $this->db->where (MysqliDb::$prefix . $this->dbTable . '.' . $this->primaryKey, $id);
return $this->getOne ($fields); return $this->getOne ($fields);
} }
...@@ -310,7 +312,7 @@ class dbObject { ...@@ -310,7 +312,7 @@ class dbObject {
* *
* @return dbObject * @return dbObject
*/ */
private function getOne ($fields = null) { protected function getOne ($fields = null) {
$this->processHasOneWith (); $this->processHasOneWith ();
$results = $this->db->ArrayBuilder()->getOne ($this->dbTable, $fields); $results = $this->db->ArrayBuilder()->getOne ($this->dbTable, $fields);
if ($this->db->count == 0) if ($this->db->count == 0)
...@@ -340,7 +342,7 @@ class dbObject { ...@@ -340,7 +342,7 @@ class dbObject {
* *
* @return array Array of dbObjects * @return array Array of dbObjects
*/ */
private function get ($limit = null, $fields = null) { protected function get ($limit = null, $fields = null) {
$objects = Array (); $objects = Array ();
$this->processHasOneWith (); $this->processHasOneWith ();
$results = $this->db->ArrayBuilder()->get ($this->dbTable, $limit, $fields); $results = $this->db->ArrayBuilder()->get ($this->dbTable, $limit, $fields);
...@@ -409,9 +411,11 @@ class dbObject { ...@@ -409,9 +411,11 @@ class dbObject {
* *
* @return int * @return int
*/ */
private function count () { protected function count () {
$res = $this->db->ArrayBuilder()->getValue ($this->dbTable, "count(*)"); $res = $this->db->ArrayBuilder()->getValue ($this->dbTable, "count(*)");
return $res['cnt']; if (!$res)
return 0;
return $res;
} }
/** /**
...@@ -608,6 +612,9 @@ class dbObject { ...@@ -608,6 +612,9 @@ class dbObject {
case "int": case "int":
$regexp = "/^[0-9]*$/"; $regexp = "/^[0-9]*$/";
break; break;
case "double":
$regexp = "/^[0-9\.]*$/";
break;
case "bool": case "bool":
$regexp = '/^[yes|no|0|1|true|false]$/i'; $regexp = '/^[yes|no|0|1|true|false]$/i';
break; break;
......
...@@ -141,6 +141,12 @@ if (!is_array ($products[0]['userId']) || !is_array ($products[1]['userId'])) { ...@@ -141,6 +141,12 @@ if (!is_array ($products[0]['userId']) || !is_array ($products[1]['userId'])) {
exit; exit;
} }
$products = product::with('userId')->ArrayBuilder()->get(2);
if (!is_array ($products[0]['userId']) || !is_array ($products[1]['userId'])) {
echo "Error in with processing in get";
exit;
}
$depts = product::join('user')->orderBy('`products`.id', 'desc')->get(5); $depts = product::join('user')->orderBy('`products`.id', 'desc')->get(5);
foreach ($depts as $d) { foreach ($depts as $d) {
if (!is_object($d)) { if (!is_object($d)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment