protected function execute($sqlId, $params, &$sql, $limit = false, $nrows = -1, $offset = -1, $order = '', $sort = '') { $this->select = $sqlId; if ($limit) { $this->select = jqGridDB::limit($this->select, $this->dbtype, $nrows, $offset, $order, $sort); } if ($this->debug) { $this->logQuery($this->select, $params); } $sql = $this->parseSql($this->select, $params); if ($sql) { return jqGridDB::execute($sql, $params); } else { return false; } }
/** * Executes a prepared sql statement. Also if limit is set to true is used * to return limited set of records * Return true on success * @param string $sqlId - sql to pe executed * @param array $params - array of values which are passed as parameters * to the sql * @param resource $sql - pointer to the constructed sql * @param boolean $limit - if set to true we use a pagging mechanizm * @param integer $nrows - number of rows to return * @param integer $offset - the offset from which the nrows should be returned * @return boolean */ protected function execute($sqlId, $params, &$sql, $limit = false, $nrows = -1, $offset = -1, $order = '', $sort = '') { if ($this->dbtype == 'mongodb') { return jqGridDB::mongoexecute($sqlId, $params, $sql, $limit, $nrows = 0, $offset, $order, $sort, $this->mongofields); } if ($this->dbtype == 'array') { if ($params && is_array($params)) { foreach ($params as $k => $v) { $params[$k] = "'" . $v . "'"; } } } $this->select = $sqlId; if ($limit) { $this->select = jqGridDB::limit($this->select, $this->dbtype, $nrows, $offset, $order, $sort); } if ($this->debug) { $this->logQuery($this->select, $params); } try { $sql = $this->parseSql($this->select, $params); $ret = true; if ($sql) { $ret = jqGridDB::execute($sql, $params); } //DB2 if (!$ret) { $this->errorMessage = jqGridDB::errorMessage($this->pdo); throw new Exception($this->errorMessage); } } catch (Exception $e) { if (!$this->errorMessage) { $this->errorMessage = $e->getMessage(); } if ($this->showError) { $this->sendErrorHeader(); } else { echo $this->errorMessage; } return false; } return true; }
/** * This method is internally used to get the data. * @return array */ private function getACData() { $result = array(); if (strlen($this->SelectCommand) > 0) { $prmlen = substr_count($this->SelectCommand, "?"); if ($prmlen > 0) { $params = array(); if (strtolower($this->encoding) != 'utf-8') { $this->term = iconv("utf-8", $this->encoding . "//TRANSLIT", $this->term); } for ($i = 1; $i <= $prmlen; $i++) { switch ($this->searchType) { case 'startWith': array_push($params, $this->term . "%"); break; case 'contain': array_push($params, "%" . $this->term . "%"); break; case 'endWith': array_push($params, "%" . $this->term); break; default: array_push($params, $this->term); break; } } } else { $params = null; } if ($this->itemLength > 0 && !$this->loadAll) { $sqlCmd = jqGridDB::limit($this->SelectCommand, $this->dbtype, $this->itemLength, 0); } else { $sqlCmd = $this->SelectCommand; } $sql1 = jqGridDB::prepare($this->conn, $sqlCmd, $params, true); $ret = jqGridDB::execute($sql1, $params); $ncols = jqGridDB::columnCount($sql1); // Mysqli hack if ($this->dbtype == 'mysqli') { $fld = $sql1->field_count; //start the count from 1. First value has to be a reference to the stmt. because bind_param requires the link to $stmt as the first param. $count = 1; $fieldnames[0] =& $sql1; for ($i = 0; $i < $ncols; $i++) { $fieldnames[$i + 1] =& $res_arr[$i]; //load the fieldnames into an array. } call_user_func_array('mysqli_stmt_bind_result', $fieldnames); } while ($row = jqGridDB::fetch_num($sql1)) { if ($this->dbtype == 'mysqli') { $row = $res_arr; } if ($ncols == 1) { array_push($result, array("value" => $row[0], "label" => $row[0])); } else { if ($ncols == 2) { array_push($result, array("value" => $row[0], "label" => $row[1])); } else { if ($ncols >= 3) { array_push($result, array("value" => $row[0], "label" => $row[1], "id" => $row[2])); } } } } jqGridDB::closeCursor($sql1); } return $result; }
/** * Return a array representation of the sql query. Also return only the * the values of the first column * @param string $sql The sql query string * @param array $params array of parameters passed to the query * @param mixed $limit the number of records to retrieve. if false - all * @param number $offset how many record to skip. 0 - none * @return array of the values of the first column of the query */ protected function getSQLSerie($sql, $params = null, $limit = false, $offset = 0) { $retarr = array(); if ($this->dbtype != 'chartarray' && $this->conn) { try { if ($limit && $limit > 0) { $sql = jqGridDB::limit($sql, $this->dbtype, $limit, $offset); } $sersql = jqGridDB::prepare($this->conn, $sql, $params, true); jqGridDB::execute($sersql, $params); $xy = false; $ncols = jqGridDB::columnCount($sersql); if ($ncols > 1) { $xy = true; } for ($i = 0; $i < $ncols; $i++) { $field = jqGridDB::getColumnMeta($i, $sersql); $typearr[$i] = jqGridDB::MetaType($field, $this->dbtype); } while ($r = jqGridDB::fetch_num($sersql)) { $retarr[] = $xy ? array($this->convertVar($r[0], $typearr[0]), $this->convertVar($r[1], $typearr[1])) : $this->convertVar($r[0], $typearr[0]); } jqGridDB::closeCursor($sersql); } catch (Exception $e) { echo $e->getMessage(); return false; } } return $retarr; }
//var_dump($sqlstr); if ($action == 'test') { if ($dbtype == 'mysql' || $dbtype == 'pgsql' || $dbtype == 'sqlite') { echo pdo_test_connection($connstr, $dbtype); } } // var_dump($action); if ($action == 'genform') { if ($dbtype == 'mysql' || $dbtype == 'pgsql' || $dbtype == 'sqlite') { include '../php/jqGridPdo.php'; ini_set("display_errors", 1); $info = parse_connection_string($connstr); try { $conn = new PDO($dbtype . ':host=' . $info->host . ';dbname=' . $info->database, $info->user_id, $info->password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sqlstr = jqGridDB::limit($sqlstr, $dbtype, 1, 0); //var_dump($sqlstr); $stmt = jqGridDB::prepare($conn, $sqlstr, null); $ret = jqGridDB::execute($stmt); $metasql = array(); if ($ret) { $meta = array(); $colcount = jqGridDB::columnCount($stmt, null); for ($i = 0; $i < $colcount; $i++) { $meta = jqGridDB::getColumnMeta($i, $stmt); $metasql[] = array("name" => $meta['name'], "type" => jqGridDB::MetaType($meta, $dbtype), "len" => $meta['len']); } } jqGridDB::closeCursor($stmt); echo json_encode(array("msg" => "success", "rows" => $metasql)); } catch (Exception $e) {