18 require_once dirname(__FILE__).
'/../DAL/DAL.inc';
55 parent::__construct();
76 public static function getQuery($systemid, $queryid, $params=Array(), $bindValues=TRUE)
79 $class = $systemid.
'Queries';
80 $function =
'prepare'.$queryid.
'Query';
82 self::requireQueryClass($systemid);
85 if (method_exists($class, $function) === FALSE) {
87 throw new DALException(
'Could not load query '.$queryid.
' in system '.$systemid);
89 return call_user_func(array($class, $function), $params, $bindValues);
108 $query = self::getQuery($systemid, $queryid, $params);
109 return self::getGrouped($query);
125 $query = self::getQuery($systemid, $queryid, $params);
126 return self::getGroupedAssoc($query);
143 public static function executeAssoc($systemid, $queryid, $col=NULL, $params=Array())
145 if ((func_num_args() === 3) && is_array($col)) {
149 $query = self::getQuery($systemid, $queryid, $params);
150 $res = self::getAssoc($query, $col);
168 public static function executeAll($systemid, $queryid, $params=Array())
170 $query = self::getQuery($systemid, $queryid, $params);
171 return self::getAll($query);
187 public static function executeOne($systemid, $queryid, $params=Array())
189 $query = self::getQuery($systemid, $queryid, $params);
190 $result = self::getOne($query);
194 if (is_resource($result) === TRUE) {
195 $result = stream_get_contents($result);
216 public static function executeQuery($systemid, $queryid=NULL, $params=Array())
219 if (($systemid instanceof
Query) === TRUE) {
220 self::_startQueryTimer($systemid);
221 $dalQuery = $systemid;
222 $query = $dalQuery->prepare();
223 }
else if ($queryid === NULL) {
224 throw new DALException(
'No queryid provided for executeQuery.');
226 $dalQuery = self::getQuery($systemid, $queryid, $params);
227 self::_startQueryTimer($dalQuery);
228 $query = $dalQuery->prepare();
232 self::execPdoQuery($query);
233 }
catch (PDOException $e) {
237 if (self::getDbType() ==
'oci') {
239 $dalQuery->releaseLobs();
240 $rows = oci_num_rows($query);
242 $rows = (int)$query->rowCount();
250 self::_endQueryTimer();
275 $dbh = self::getDb();
276 $db_type = self::getDbType();
278 if ($db_type ===
'oci') {
280 $query = oci_parse($dbh, $sql);
282 $query = $dbh->prepare($sql);
310 $dbh = self::getDb();
311 $db_type = self::getDbType();
313 if ($db_type ===
'oci') {
316 if ($dataType ==
'PDO::PARAM_LOB') {
317 $lob = oci_new_descriptor($dbh);
319 $ret_val = oci_bind_by_name($query,
':'.$name, $lob, SQLT_CLOB);
321 $ret_val = oci_bind_by_name($query,
':'.$name, $value);
323 if ($ret_val === FALSE) {
324 $oci_error = oci_error($query);
325 throw new Exception(
'Unable to bind variable "'.$name.
'" to query: '.$oci_error[
'code'].
' '.$oci_error[
'message']);
328 if ($dataType === NULL) {
329 $query->bindValue(
':'.$name, $value);
331 $query->bindValue(
':'.$name, $value, $dataType);
358 $dbh = self::getDb();
359 $db_type = self::getDbType();
361 if ($db_type ===
'oci') {
364 if ($dataType ==
'PDO::PARAM_LOB') {
365 $lob = oci_new_descriptor($dbh);
367 $ret_val = oci_bind_by_name($query,
':'.$name, $lob, SQLT_CLOB);
369 if ($dataType & PDO::PARAM_INPUT_OUTPUT) {
370 $ret_val = oci_bind_by_name($query,
':'.$name, $value, $maxLength);
372 $ret_val = oci_bind_by_name($query,
':'.$name, $value);
375 $oci_error = oci_error($query);
376 throw new DALException(
'Unable to bind Oracle variable by reference: '.$oci_error[
'code'].
' '.$oci_error[
'message']);
380 if ($dataType === NULL) {
381 $query->bindValue(
':'.$name, $value);
383 $query->bindValue(
':'.$name, $value, $dataType, $maxLength);
419 if ($dataType === NULL) {
420 return 'PDO::PARAM_STR';
424 switch (strtoupper($dataType)) {
430 case 'DOUBLE PRECISION':
432 $pdoType =
'PDO::PARAM_INT';
435 $pdoType =
'PDO::PARAM_BOOL';
438 $pdoType =
'PDO::PARAM_STR';
463 public static function quote($value)
465 $quoted_value = NULL;
466 if (self::getDbType() ==
'oci') {
468 $quoted_value =
'\''.str_replace(
'\'',
'\'\
'', $value).
'\'';
471 $quoted_value = $db->quote($value);
472 if ($quoted_value === FALSE) {
474 $quoted_value =
'\''.str_replace(
'\'',
'\'\
'', $value).
'\'';
478 return $quoted_value;