ElasticDB: Prepare for insert
This commit is contained in:
parent
4b6d02cdf8
commit
6103758e68
|
@ -115,7 +115,6 @@ if (isset($_GET["mongo"])) {
|
||||||
|
|
||||||
class Min_Driver extends Min_SQL {
|
class Min_Driver extends Min_SQL {
|
||||||
function select($table, $select, $where, $group, $order, $limit, $page, $print = false) {
|
function select($table, $select, $where, $group, $order, $limit, $page, $print = false) {
|
||||||
global $connection;
|
|
||||||
$select = ($select == array("*")
|
$select = ($select == array("*")
|
||||||
? array()
|
? array()
|
||||||
: array_fill_keys($select, true)
|
: array_fill_keys($select, true)
|
||||||
|
@ -125,13 +124,25 @@ if (isset($_GET["mongo"])) {
|
||||||
$val = preg_replace('~ DESC$~', '', $val, 1, $count);
|
$val = preg_replace('~ DESC$~', '', $val, 1, $count);
|
||||||
$sort[$val] = ($count ? -1 : 1);
|
$sort[$val] = ($count ? -1 : 1);
|
||||||
}
|
}
|
||||||
return new Min_Result(iterator_to_array($connection->_db->selectCollection($table)
|
return new Min_Result(iterator_to_array($this->_conn->_db->selectCollection($table)
|
||||||
->find(array(), $select)
|
->find(array(), $select)
|
||||||
->sort($sort)
|
->sort($sort)
|
||||||
->limit(+$limit)
|
->limit(+$limit)
|
||||||
->skip($page * $limit)
|
->skip($page * $limit)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function insert($table, $set) {
|
||||||
|
try {
|
||||||
|
$return = $this->_conn->_db->selectCollection($table)->insert($set);
|
||||||
|
$this->_conn->errno = $return['code'];
|
||||||
|
$this->_conn->error = $return['err'];
|
||||||
|
return !$return['err'];
|
||||||
|
} catch (Exception $ex) {
|
||||||
|
$this->_conn->error = $ex->getMessage();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -98,18 +98,17 @@ if ($_POST["save"]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!support("table") && !$fields) {
|
if (!support("table") && !$fields) {
|
||||||
|
$id = ($jush == "mongo" ? "_id" : "itemName()"); // simpledb
|
||||||
if (!$where) { // insert
|
if (!$where) { // insert
|
||||||
$row = reset(get_rows("SELECT * FROM " . table($TABLE) . " LIMIT 1"));
|
$row = $driver->select($TABLE, array("*"), $where, array("*"), array(), 1, 0);
|
||||||
if (!$row) {
|
$row = ($row ? $row->fetch_assoc() : array($id => ""));
|
||||||
$row = array("itemName()" => "");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if ($row) {
|
if ($row) {
|
||||||
foreach ($row as $key => $val) {
|
foreach ($row as $key => $val) {
|
||||||
if (!$where) {
|
if (!$where) {
|
||||||
$row[$key] = null;
|
$row[$key] = null;
|
||||||
}
|
}
|
||||||
$fields[$key] = array("field" => $key, "null" => ($key != "itemName()"), "auto_increment" => ($key == "itemName()"));
|
$fields[$key] = array("field" => $key, "null" => ($key != $id), "auto_increment" => ($key == $id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue