Пример #1
0
 public function delete(array $data)
 {
     $result = false;
     if (!$this->del) {
         return $result;
     }
     $ide = null;
     $binds = array(&$ide);
     $types = array();
     if (count($data) > 0) {
         $id = $this->getPrimaryKeyId();
         if (!isset($data[$id])) {
             return $result;
         }
         $sql = "DELETE FROM " . $this->table . " WHERE " . $id . "=?";
         $stmt = $this->parseSql($sql, $binds, false);
         $delids = explode(",", $data[$id]);
         $types[0] = 'custom';
         if ($stmt) {
             if ($this->trans) {
                 jqGridDB::beginTransaction($this->pdo);
                 foreach ($delids as $i => $ide) {
                     $delids[$i] = trim($delids[$i]);
                     $binds[0] =& $delids[$i];
                     if ($this->debug) {
                         $this->logQuery($sql, $binds, $types, $data, $this->fields, $this->primaryKey);
                     }
                     jqGridDB::bindValues($stmt, $binds, $types);
                     $test = jqGridDB::execute($stmt, $binds);
                     if (!$test) {
                         jqGridDB::rollBack($this->pdo);
                         break;
                         $result = false;
                     }
                     unset($binds[0]);
                 }
                 if ($test) {
                     $result = jqGridDB::commit($this->pdo);
                 }
             } else {
                 foreach ($delids as $i => $ide) {
                     $delids[$i] = trim($delids[$i]);
                     $binds[0] =& $delids[$i];
                     if ($this->debug) {
                         $this->logQuery($sql, $binds, $types, $data, $this->fields, $this->primaryKey);
                     }
                     jqGridDB::bindValues($stmt, $binds, $types);
                     $test = jqGridDB::execute($stmt, $binds);
                     if (!$test) {
                         break;
                         $result = false;
                     }
                     unset($binds[0]);
                 }
                 $result = true;
             }
             jqGridDB::closeCursor($stmt);
         }
     }
     if ($this->debug) {
         $this->debugout();
     }
     return $result;
 }
Пример #2
0
 /**
  *
  * Delete the data into the database according the table element
  * A primaryKey should be set. If the key is not set It can be obtained
  * from jqGridDB::getPrimaryKey
  * Return true on success, false when the operation is not succefull
  * @todo possibility to set additional where clause
  * @param array $data associative array which key values correspond to the
  * names in the delete command
  * @return boolean
  */
 public function delete(array $data, $where = '', array $params = null)
 {
     $result = false;
     if (!$this->del) {
         return $result;
     }
     //SQL Server hack
     if (!$this->checkPrimary()) {
         return $result;
     }
     $ide = null;
     $binds = array(&$ide);
     $types = array();
     if (count($data) > 0) {
         if ($where && strlen($where) > 0) {
             $id = "";
             $sql = "DELETE FROM " . $this->table . " WHERE " . $where;
             $stmt = $this->parseSql($sql, $params);
             $delids = "";
             $custom = true;
         } else {
             $id = $this->getPrimaryKeyId();
             if (!isset($data[$id])) {
                 $this->errorMessage = "Missed data id value to perform delete!";
                 if ($this->showError) {
                     $this->sendErrorHeader();
                 }
                 return $result;
             }
             $sql = "DELETE FROM " . $this->table . " WHERE " . $id . "=?";
             $stmt = $this->parseSql($sql, $binds, false);
             $delids = explode(",", $data[$id]);
             $custom = false;
         }
         $types[0] = 'custom';
         if ($stmt) {
             if ($this->trans) {
                 try {
                     jqGridDB::beginTransaction($this->pdo);
                     $result = $this->_actionsCRUDGrid('del', 'before');
                     if ($custom) {
                         if ($this->debug) {
                             $this->logQuery($sql, $params, false, $data, null, $this->primaryKey);
                         }
                         $result = jqGridDB::execute($stmt, $params);
                     } else {
                         foreach ($delids as $i => $ide) {
                             $delids[$i] = trim($delids[$i]);
                             $binds[0] =& $delids[$i];
                             if ($this->debug) {
                                 $this->logQuery($sql, $binds, $types, $data, $this->fields, $this->primaryKey);
                             }
                             jqGridDB::bindValues($stmt, $binds, $types);
                             $result = jqGridDB::execute($stmt, $binds);
                             if (!$result) {
                                 break;
                             }
                             unset($binds[0]);
                         }
                     }
                     jqGridDB::closeCursor($stmt);
                     if ($result) {
                         $result = $this->_actionsCRUDGrid('del', 'after');
                     }
                     if ($result) {
                         jqGridDB::commit($this->pdo);
                     } else {
                         $this->errorMessage = jqGridDB::errorMessage($this->pdo);
                         throw new Exception($this->errorMessage);
                     }
                 } catch (Exception $e) {
                     jqGridDB::rollBack($this->pdo);
                     $result = false;
                     if (!$this->errorMessage) {
                         $this->errorMessage = $e->getMessage();
                     }
                 }
             } else {
                 try {
                     $result = $this->_actionsCRUDGrid('del', 'before');
                     if ($result) {
                         if ($custom) {
                             $result = jqGridDB::execute($stmt, $params);
                         } else {
                             foreach ($delids as $i => $ide) {
                                 $delids[$i] = trim($delids[$i]);
                                 $binds[0] =& $delids[$i];
                                 if ($this->debug) {
                                     $this->logQuery($sql, $binds, $types, $data, $this->fields, $this->primaryKey);
                                 }
                                 jqGridDB::bindValues($stmt, $binds, $types);
                                 $result = jqGridDB::execute($stmt, $binds);
                                 if (!$result) {
                                     break;
                                 }
                                 unset($binds[0]);
                             }
                         }
                     }
                     jqGridDB::closeCursor($stmt);
                     if ($result) {
                         $result = $this->_actionsCRUDGrid('del', 'after');
                     }
                     if (!$result) {
                         $this->errorMessage = jqGridDB::errorMessage($this->pdo);
                         throw new Exception($this->errorMessage);
                     }
                 } catch (Exception $e) {
                     $result = false;
                     if (!$this->errorMessage) {
                         $this->errorMessage = $e->getMessage();
                     }
                 }
             }
         }
     }
     if ($this->debug) {
         $this->debugout();
     }
     if ($this->showError && !$result) {
         $this->sendErrorHeader();
     }
     return $result;
 }
Пример #3
0
 /**
  * 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;
 }
Пример #4
0
 public function getEvents($start, $end)
 {
     if (!empty($this->user_id) && !empty($this->table)) {
         $sql = "SELECT ";
         $i = 0;
         foreach ($this->dbmap as $k => $v) {
             $sql .= $i == 0 ? $k . ' AS ' . $v : ', ' . $k . ' AS ' . $v;
             $i++;
         }
         if (strlen($this->searchwhere) > 0) {
             $sql .= ' FROM ' . $this->table . ' WHERE ' . $this->searchwhere . ' AND (user_id = ?) ORDER BY start DESC';
             $params = $this->searchdata;
             $params[] = (int) $this->user_id;
         } else {
             $sql .= ' FROM ' . $this->table . ' WHERE user_id = ? AND start >= ? AND start <= ? ORDER BY start';
             $params = array((int) $this->user_id, (int) $start, (int) $end);
         }
         $query = jqGridDB::prepare($this->db, $sql, $params);
         $ret = jqGridDB::execute($query);
         $ev = array();
         while ($row = jqGridDB::fetch_assoc($query, $this->db)) {
             $row[$this->dbmap['all_day']] = $row[$this->dbmap['all_day']] == 1 ? true : false;
             $ev[] = $row;
         }
         jqGridDB::closeCursor($query);
         return $ev;
     } else {
         return false;
     }
 }
Пример #5
0
 /**
  * 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;
 }
Пример #6
0
        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) {
            echo json_encode(array("msg" => $e->getMessage()));
        }
    }
Пример #7
0
 public function getEvents($start, $end)
 {
     if (!empty($this->user_id) && !empty($this->table)) {
         $sql = "SELECT ";
         $i = 0;
         foreach ($this->dbmap as $k => $v) {
             $sql .= $i == 0 ? $k . ' AS ' . $v : ', ' . $k . ' AS ' . $v;
             $i++;
         }
         $sql .= ' FROM ' . $this->table . ' WHERE ';
         if ($this->wherecond && strlen($this->wherecond) > 0) {
             $pos = stripos($this->wherecond, 'where');
             if ($pos !== false) {
                 $this->wherecond = substr_replace($this->wherecond, "", $pos, 5);
             }
             $sql .= $this->wherecond . ' AND ';
         }
         $sqluser = "******";
         if (is_array($this->user_id)) {
             foreach ($this->user_id as $k => $v) {
                 if ($k != 0) {
                     $sqluser .= " OR user_id = ? ";
                 } else {
                     $sqluser .= " user_id = ? ";
                 }
             }
         } else {
             $sqluser .= " user_id = ? ";
         }
         $sqluser .= ")";
         if (strlen($this->searchwhere) > 0) {
             $sql .= $this->searchwhere . ' AND ' . $sqluser . ' ORDER BY start DESC';
             $params = $this->whereparams;
             foreach ($this->searchdata as $k => $v) {
                 $params[] = $v;
             }
             //$params[]
             if (is_array($this->user_id)) {
                 foreach ($this->user_id as $k => $v) {
                     $params[] = $v;
                 }
             } else {
                 $params[] = $this->user_id;
             }
         } else {
             $sql .= $sqluser . ' AND start >= ? AND start <= ? ORDER BY start';
             $params = $this->whereparams;
             //$params[]
             if (is_array($this->user_id)) {
                 foreach ($this->user_id as $k => $v) {
                     $params[] = $v;
                 }
             } else {
                 $params[] = $this->user_id;
             }
             $params[] = (int) $start;
             $params[] = (int) $end;
         }
         $query = jqGridDB::prepare($this->db, $sql, $params);
         $ret = jqGridDB::execute($query, $params);
         $ev = array();
         while ($row = jqGridDB::fetch_assoc($query, $this->db)) {
             $row[$this->dbmap['all_day']] = $row[$this->dbmap['all_day']] == 1 ? true : false;
             $ev[] = $row;
         }
         jqGridDB::closeCursor($query);
         return $ev;
     } else {
         return false;
     }
 }