public function checkExisted($stock_id) { $ps = new PreparedStatement('SELECT id FROM transfer_bills WHERE source_stock_id = ? OR destination_stock_id = ?'); $ps->setInt(1, $stock_id); $ps->setInt(2, $stock_id); $rs = $this->ds->execute($ps->getSql()); $ret = FALSE; if (mysql_fetch_array($rs)) { $ret = TRUE; } mysql_free_result($rs); return $ret; }
public function delete($id) { if ($this->checkExistedInBills($id)) { return 1; } $ps = new PreparedStatement("DELETE FROM stocks WHERE id = ?"); $ps->setInt(1, $id); return $this->ds->execute($ps->getSql()) ? 0 : 2; }
public function findByIdPS($id, $queryOperator = '=', $orderBy = null, $offset = 0, $limit = 0) { if (!in_array($queryOperator, self::$ALLOWED_NUMERIC_QUERY_OPERATORS)) { $queryOperator = self::$ALLOWED_NUMERIC_QUERY_OPERATORS[0]; } $ps = new PreparedStatement("select * from appperm where id {$queryOperator} ?" . ($orderBy !== null && $orderBy != '' ? ' order by ' . $orderBy : ''), $offset, $limit); $ps->setInt($id); return $ps; }
function delete($id) { $sql = 'DELETE FROM carts WHERE id = ?'; $ps = new PreparedStatement($sql); $ps->setInt(1, $id); $this->ds->execute($ps->getSql()); $cartItemDAO = new CartItemDAO($this->ds); $cartItemDAO->deleteInCart($id); }
public function delete($id) { $ps = new PreparedStatement("DELETE FROM categories WHERE id = ?"); $ps->setInt(1, $id); if ($this->ds->execute($ps->getSql())) { $productDAO = new ProductDAO($this->ds); $productDAO->updateCat($id, 'NULL'); return TRUE; } return FALSE; }
public function delete($id) { $ps = new PreparedStatement("DELETE FROM cities WHERE id = ?"); $ps->setInt(1, $id); if ($this->ds->execute($ps->getSql())) { $customerDAO = new CustomerDAO($this->ds); $customerDAO->updateCity($id, 'NULL'); return TRUE; } return FALSE; }
public function validate($db, &$row) { $sql = sprintf('select %s from %s', $this->foreignKeyMapping[0]->foreign, $this->foreignTable); $sep = ' where '; foreach ($this->foreignKeyMapping as $fkm) { $sql .= sprintf('%s%s = ?', $sep, $fkm->foreign); if ($sep != ' and ') { $sep = ' and '; } } $ps = new PreparedStatement($sql, 0, 1); foreach ($this->foreignKeyMapping as $fkm) { $vn = $fkm->local; $val = property_exists($row, $vn) ? $row->{$vn} : ''; // If we're set to allow nulls and any value is null, don't validate. if ($this->allowNULL && $val === null) { return ''; } switch ($fkm->type) { case 'int': $ps->setInt($val); break; case 'float': $ps->setFloat($val); break; case 'double': $ps->setDouble($val); break; case 'boolean': $ps->setBoolean($val); break; case 'string': $ps->setString($val); break; case 'binary': $ps->setBinary($val); break; default: throw new Exception(sprintf('Unexpected PreparedStatement data type: %s', $fkm->type)); } } if (!$db->fetchObject($db->executeQuery($ps), true)) { if ($this->errorMsg != '') { return $this->errorMsg; } return _t('ForeignKeyValidator.class.errorMsg.mustMatchAnExistingEntry'); } return ''; }
public static function hasPermissions($user_id, $permissions) { if (!is_array($permissions)) { $permissions = explode(',', $permissions); } $fileCache = self::createFileCache(); $cacheKey = sprintf('appuser%dHasPerms%s', $user_id, implode(',', $permissions)); if (($val = $fileCache->get($cacheKey)) !== false) { return $val != 0 ? true : false; } $db = ConnectionFactory::getConnection(); $ps = new PreparedStatement(<<<EOF select distinct p.perm_name from appuserrole u_r inner join approle r on r.role_name = u_r.role_name inner join approleperm r_p on r_p.role_name = r.role_name inner join appperm p on p.perm_name = r_p.perm_name where u_r.user_id = ? order by p.perm_name EOF ); $ps->setInt($user_id); $userPerms = array(); $rs = $db->executeQuery($ps); while ($r = $db->fetchObject($rs)) { $userPerms[] = $r->perm_name; } $db->freeResult($rs); $db->close(); $hasAllPermissions = true; if (!in_array('all', $userPerms)) { foreach ($permissions as $perm) { $perm = trim($perm); if ($perm != '' && !in_array($perm, $userPerms)) { $hasAllPermissions = false; break; } } } $fileCache->set($cacheKey, $hasAllPermissions ? 1 : 0); return $hasAllPermissions; }
public function validate($db, &$row) { $sql = sprintf('select %s from %s', $this->fields[0]->field, $this->table); $sep = ' where '; foreach ($this->fields as $fld) { $qo = $fld->queryOperator; if ($qo == 'beginsWith' || $qo == 'contains' || $qo == 'endsWith') { $qo = 'like'; } $sql .= sprintf('%s%s %s ?', $sep, $fld->field, $qo); if ($sep != ' and ') { $sep = ' and '; } } $ps = new PreparedStatement($sql, 0, 1); foreach ($this->fields as $fld) { $vn = $fld->field; $val = property_exists($row, $vn) ? $row->{$vn} : ''; // If we're set to allow nulls and any value is null, don't validate. if ($this->allowNULL && $val === null) { return ''; } switch ($fld->type) { case 'int': $ps->setInt($val); break; case 'float': $ps->setFloat($val); break; case 'double': $ps->setDouble($val); break; case 'boolean': $ps->setBoolean($val); break; case 'string': switch ($fld->queryOperator) { case 'beginsWith': $ps->setString($val . '%'); break; case 'contains': $ps->setString('%' . $val . '%'); break; case 'endsWith': $ps->setString('%' . $val); break; default: $ps->setString($val); break; } break; case 'binary': $ps->setBinary($val); break; default: throw new Exception(sprintf('Unexpected PreparedStatement data type: %s', $fld->type)); } } if ($db->fetchObject($db->executeQuery($ps), true)) { if ($this->errorMsg != '') { return $this->errorMsg; } return _t('NoDuplicatesValidator.class.errorMsg.anEntryAlreadyExistsWithThisValue'); } return ''; }
private function findMaxOrderInCat($cat_id) { $sql = 'SELECT MAX(order_in_cat) AS max_order FROM products WHERE category_id = ?'; $ps = new PreparedStatement($sql); $ps->setInt(1, $cat_id); $rs = $this->ds->execute($ps->getSql()); $max_order = 0; if ($row = mysql_fetch_array($rs)) { $max_order = (int) $row['max_order']; } mysql_free_result($rs); return $max_order; }
public function deleteInCart($cart_id) { $ps = new PreparedStatement('DELETE FROM cart_items WHERE cart_id = ?'); $ps->setInt(1, $cart_id); return $this->ds->execute($ps->getSql()); }
$ps->setInt($query); $ps->setInt($queryCol == '' || $queryCol == 'pri.description' ? 1 : 0); $ps->setString('%' . $query . '%'); $ps->setInt($queryCol == '' || $queryCol == 'pri.acct_no' ? 1 : 0); $ps->setString('%' . $query . '%'); $ps->setInt($queryCol == '' || $queryCol == 'pri.ticker_symbol' ? 1 : 0); $ps->setString('%' . $query . '%'); $row = $db->fetchObject($db->executeQuery($ps), true); $rowCount = isset($row->rowCount) ? (int) $row->rowCount : 0; printf('{"sEcho": %d, "iTotalRecords": %d, "iTotalDisplayRecords": %d, "aaData": [', $sEcho, $rowCount, $rowCount); // Get actual rows. $ps = new PreparedStatement(<<<EOF select pri.* EOF . $sqlTail . $orderBy, $offset, $limit); $ps->setInt($queryCol == '' || $queryCol == 'pri.id' ? 1 : 0); $ps->setInt($query); $ps->setInt($queryCol == '' || $queryCol == 'pri.description' ? 1 : 0); $ps->setString('%' . $query . '%'); $ps->setInt($queryCol == '' || $queryCol == 'pri.acct_no' ? 1 : 0); $ps->setString('%' . $query . '%'); $ps->setInt($queryCol == '' || $queryCol == 'pri.ticker_symbol' ? 1 : 0); $ps->setString('%' . $query . '%'); $rows = $db->fetchAllObjects($db->executeQuery($ps), true); $sep = ''; foreach ($rows as $row) { $arr = array(); foreach ($returnColumns as $dc) { $arr[] = isset($row->{$dc}) ? $row->{$dc} : ''; } echo $sep;
function delete($id) { $sql = 'DELETE FROM promos WHERE id = ?'; $ps = new PreparedStatement($sql); $ps->setInt(1, $id); return $this->ds->execute($ps->getSql()) ? TRUE : FALSE; }
$ps->setInt($queryCol == '' || $queryCol == 'pri.last_name' ? 1 : 0); if ($canDoFulltextSearch) { $ps->setString($ftquery); $ps->setString($ftquery); } else { $ps->setString('%' . $query . '%'); } $row = $db->fetchObject($db->executeQuery($ps), true); $rowCount = isset($row->rowCount) ? (int) $row->rowCount : 0; printf('{"sEcho": %d, "iTotalRecords": %d, "iTotalDisplayRecords": %d, "aaData": [', $sEcho, $rowCount, $rowCount); // Get actual rows. $ps = new PreparedStatement(<<<EOF select pri.* EOF . $sqlTail . $orderBy, $offset, $limit); $ps->setInt($queryCol == '' || $queryCol == 'pri.id' ? 1 : 0); $ps->setInt($query); $ps->setInt($queryCol == '' || $queryCol == 'pri.user_name' ? 1 : 0); $ps->setString($query . '%'); $ps->setInt($queryCol == '' || $queryCol == 'pri.email_addr' ? 1 : 0); $ps->setString($query . '%'); $ps->setInt($queryCol == '' || $queryCol == 'pri.first_name' ? 1 : 0); if ($canDoFulltextSearch) { $ps->setString($ftquery); $ps->setString($ftquery); } else { $ps->setString('%' . $query . '%'); } $ps->setInt($queryCol == '' || $queryCol == 'pri.last_name' ? 1 : 0); if ($canDoFulltextSearch) { $ps->setString($ftquery);
<?php // DO NOT EDIT THIS FILE. // This file was generated by searchgen. // If you need to customize this file, please edit the corresponding // yaml file in the gencfg directory, and then re-generate this file // by running searchgen, passing in the table name. if (isset($command) && $command == 'loadIncomeexpense') { header('Content-Type: application/json'); $db = ConnectionFactory::getConnection(); $incomeexpenseDAO = new IncomeexpenseDAO($db); $id = isset($params['id']) ? (int) trim($params['id']) : 0; if ($id <= 0) { $rows = array(Incomeexpense::createDefault()); } else { $sql = <<<EOF select * from incomeexpense pri where pri.id = ? EOF; $ps = new PreparedStatement($sql, 0, 1); $ps->setInt($id); $rows = $incomeexpenseDAO->findWithPreparedStatement($ps); } echo json_encode($rows); $db->close(); exit; }
$ps = new PreparedStatement('select count(*) as rowCount' . $sqlTail); $ps->setInt($queryCol == '' || $queryCol == 'pri.id' ? 1 : 0); $ps->setInt($query); $ps->setInt($queryCol == '' || $queryCol == 'pri.role_name' ? 1 : 0); $ps->setString('%' . $query . '%'); $ps->setInt($queryCol == '' || $queryCol == 'pri.description' ? 1 : 0); $ps->setString('%' . $query . '%'); $row = $db->fetchObject($db->executeQuery($ps), true); $rowCount = isset($row->rowCount) ? (int) $row->rowCount : 0; printf('{"sEcho": %d, "iTotalRecords": %d, "iTotalDisplayRecords": %d, "aaData": [', $sEcho, $rowCount, $rowCount); // Get actual rows. $ps = new PreparedStatement(<<<EOF select pri.* EOF . $sqlTail . $orderBy, $offset, $limit); $ps->setInt($queryCol == '' || $queryCol == 'pri.id' ? 1 : 0); $ps->setInt($query); $ps->setInt($queryCol == '' || $queryCol == 'pri.role_name' ? 1 : 0); $ps->setString('%' . $query . '%'); $ps->setInt($queryCol == '' || $queryCol == 'pri.description' ? 1 : 0); $ps->setString('%' . $query . '%'); $rows = $db->fetchAllObjects($db->executeQuery($ps), true); $sep = ''; foreach ($rows as $row) { $arr = array(); foreach ($returnColumns as $dc) { $arr[] = isset($row->{$dc}) ? $row->{$dc} : ''; } echo $sep; echo json_encode($arr); if ($sep == '') {
public function updateCity($old_city_id, $new_city_id) { $sql = 'UPDATE customers SET city_id = ? WHERE city_id = ?'; $ps = new PreparedStatement($sql); if ($new_city_id == 'NULL') { $ps->setNull(1); } else { $ps->setInt(1, $new_city_id); } $ps->setInt(2, $old_city_id); $this->ds->execute($ps->getSql()); }
$ps = new PreparedStatement('select count(*) as rowCount' . $sqlTail); $ps->setInt($queryCol == '' || $queryCol == 'pri.id' ? 1 : 0); $ps->setInt($query); $ps->setInt($queryCol == '' || $queryCol == 'pri.description' ? 1 : 0); $ps->setString('%' . $query . '%'); $ps->setInt($queryCol == '' || $queryCol == 'pri.normal_sign' ? 1 : 0); $ps->setString('%' . $query . '%'); $row = $db->fetchObject($db->executeQuery($ps), true); $rowCount = isset($row->rowCount) ? (int) $row->rowCount : 0; printf('{"sEcho": %d, "iTotalRecords": %d, "iTotalDisplayRecords": %d, "aaData": [', $sEcho, $rowCount, $rowCount); // Get actual rows. $ps = new PreparedStatement(<<<EOF select pri.* EOF . $sqlTail . $orderBy, $offset, $limit); $ps->setInt($queryCol == '' || $queryCol == 'pri.id' ? 1 : 0); $ps->setInt($query); $ps->setInt($queryCol == '' || $queryCol == 'pri.description' ? 1 : 0); $ps->setString('%' . $query . '%'); $ps->setInt($queryCol == '' || $queryCol == 'pri.normal_sign' ? 1 : 0); $ps->setString('%' . $query . '%'); $rows = $db->fetchAllObjects($db->executeQuery($ps), true); $sep = ''; foreach ($rows as $row) { $arr = array(); foreach ($returnColumns as $dc) { $arr[] = isset($row->{$dc}) ? $row->{$dc} : ''; } echo $sep; echo json_encode($arr); if ($sep == '') {
} else { $id = isset($params['id']) ? (int) trim($params['id']) : 0; $sqlTail = <<<EOF from incomeexpense pri where pri.id = ? EOF; $offset = 0; $limit = 1; } $ps = new PreparedStatement(<<<EOF select pri.* EOF . $sqlTail, $offset, $limit); if ($query !== null) { $ps->setInt($query); $ps->setString('%' . $query . '%'); $ps->setString('%' . $query . '%'); } else { $ps->setInt($id); } $rs = $db->executeQuery($ps); $results = array(); while ($row = $db->fetchObject($rs)) { $results[] = array('label' => $row->id . ': ' . $row->description . ' ' . $row->normal_sign, 'value' => $row->id); } $db->freeResult($rs); echo json_encode($results); $db->close(); exit; }
// by running searchgen, passing in the table name. if (isset($command) && $command == 'loadAppuser') { header('Content-Type: application/json'); $db = ConnectionFactory::getConnection(); $appuserDAO = new AppuserDAO($db); $approleDAO = new ApproleDAO($db); $id = isset($params['id']) ? (int) trim($params['id']) : 0; if ($id <= 0) { $rows = array(Appuser::createDefault()); } else { $sql = <<<EOF select * from appuser pri where pri.id = ? EOF; $ps = new PreparedStatement($sql, 0, 1); $ps->setInt($id); $rows = $appuserDAO->findWithPreparedStatement($ps); } $ps1 = new PreparedStatement(<<<EOF select distinct r.* from appuserrole u_r inner join approle r on r.role_name = u_r.role_name where u_r.user_id = ? order by r.sort_order, r.role_name EOF , 0, 0); foreach ($rows as &$row) { $ps1->clearParams(); $ps1->setInt($row->id); $row->roles = $id <= 0 ? array() : $approleDAO->findWithPreparedStatement($ps1); } unset($row); echo json_encode($rows); $db->close(); exit; }
public function findByHas_check_noPS($has_check_no, $queryOperator = '=', $orderBy = null, $offset = 0, $limit = 0) { if (!in_array($queryOperator, self::$ALLOWED_NUMERIC_QUERY_OPERATORS)) { $queryOperator = self::$ALLOWED_NUMERIC_QUERY_OPERATORS[0]; } $ps = new PreparedStatement("select * from postingtype where has_check_no {$queryOperator} ?" . ($orderBy !== null && $orderBy != '' ? ' order by ' . $orderBy : ''), $offset, $limit); $ps->setInt($has_check_no); return $ps; }