Beispiel #1
0
 function simpleQuery($query)
 {
     $this->last_query = $query;
     $query = $this->modifyQuery($query);
     $result = @msql_query($query, $this->connection);
     if (!$result) {
         return $this->raiseError();
     }
     // Determine which queries that should return data, and which
     // should return an error code only.
     return DB::isManip($query) ? DB_OK : $result;
 }
 /**
  * Overwritten method from parent class to allow logging facility
  *
  * @param the SQL query
  *
  * @access public
  *
  * @return mixed returns a valid MySQL result for successful SELECT
  * queries, DB_OK for other successful queries.  A DB error is
  * returned on failure.
  */
 function simpleQuery($query)
 {
     if ($this->debug) {
         // to mysql server are sent not only queries passed as a parameters
         // also the simpleQuery function when special condition occurs send
         // some commands by itself, so we have to log it as well - that is
         // why this condition.
         if (!$this->autocommit && DB::isManip($query) && $this->transaction_opcount == 0) {
             echo "SET AUTOCOMMIT=0<br>";
             echo "START TRANSACTION<br>";
         }
         //echo "<pre>$query</pre>";
     }
     return parent::simpleQuery($query);
 }
Beispiel #3
0
 /**
  * Send a query to SQLite and returns the results as a SQLite resource
  * identifier.
  *
  * @param the SQL query
  * @access public
  * @return mixed returns a valid SQLite result for successful SELECT
  * queries, DB_OK for other successful queries. A DB error is
  * returned on failure.
  */
 function simpleQuery($query)
 {
     $ismanip = DB::isManip($query);
     $this->last_query = $query;
     $query = $this->_modifyQuery($query);
     $result = @sqlite_query($query, $this->connection);
     $this->result = $result;
     if (!$this->result) {
         $errno = sqlite_last_error($this->connection);
         if (!$errno) {
             return null;
         }
         return $this->sqliteRaiseError($errno);
     }
     /* sqlite_query() seems to allways return a resource */
     /* so cant use that. Using $ismanip instead          */
     if (!$ismanip) {
         $numRows = $this->numRows($result);
         /* if numRows() returned PEAR_Error */
         if (is_object($numRows)) {
             return $numRows;
         }
         return $result;
     }
     return DB_OK;
 }
Beispiel #4
0
 /**
  * Send a query to PostgreSQL and return the results as a
  * PostgreSQL resource identifier.
  *
  * @param $query the SQL query
  *
  * @return int returns a valid PostgreSQL result for successful SELECT
  * queries, DB_OK for other successful queries.  A DB error code
  * is returned on failure.
  */
 function simpleQuery($query)
 {
     $ismanip = DB::isManip($query);
     $this->last_query = $query;
     $query = $this->modifyQuery($query);
     if (!$this->autocommit && $ismanip) {
         if ($this->transaction_opcount == 0) {
             $result = @pg_exec($this->connection, 'begin;');
             if (!$result) {
                 return $this->pgsqlRaiseError();
             }
         }
         $this->transaction_opcount++;
     }
     $result = @pg_exec($this->connection, $query);
     if (!$result) {
         return $this->pgsqlRaiseError();
     }
     // Determine which queries that should return data, and which
     // should return an error code only.
     if ($ismanip) {
         $this->affected = @pg_cmdtuples($result);
         return DB_OK;
     } elseif (preg_match('/^\\s*\\(?\\s*(SELECT(?!\\s+INTO)|EXPLAIN|SHOW)\\s/si', $query)) {
         /* PostgreSQL commands:
               ABORT, ALTER, BEGIN, CLOSE, CLUSTER, COMMIT, COPY,
               CREATE, DECLARE, DELETE, DROP TABLE, EXPLAIN, FETCH,
               GRANT, INSERT, LISTEN, LOAD, LOCK, MOVE, NOTIFY, RESET,
               REVOKE, ROLLBACK, SELECT, SELECT INTO, SET, SHOW,
               UNLISTEN, UPDATE, VACUUM
            */
         $this->row[(int) $result] = 0;
         // reset the row counter.
         $numrows = $this->numrows($result);
         if (is_object($numrows)) {
             return $numrows;
         }
         $this->num_rows[(int) $result] = $numrows;
         $this->affected = 0;
         return $result;
     } else {
         $this->affected = 0;
         return DB_OK;
     }
 }
Beispiel #5
0
 /**
  * Adds LIMIT clauses to a query string according to current DBMS standards
  *
  * @param string $query   the query to modify
  * @param int    $from    the row to start to fetching (0 = the first row)
  * @param int    $count   the numbers of rows to fetch
  * @param mixed  $params  array, string or numeric data to be used in
  *                         execution of the statement.  Quantity of items
  *                         passed must match quantity of placeholders in
  *                         query:  meaning 1 placeholder for non-array
  *                         parameters or 1 placeholder per array element.
  *
  * @return string  the query string with LIMIT clauses added
  *
  * @access protected
  */
 function modifyLimitQuery($query, $from, $count, $params = array())
 {
     if (DB::isManip($query)) {
         return $query . " LIMIT {$count}";
     } else {
         return $query . " LIMIT {$from}, {$count}";
     }
 }
Beispiel #6
0
 /**
  * Send a query to SQLite and returns the results as a SQLite resource
  * identifier.
  *
  * @param the SQL query
  * @access public
  * @return mixed returns a valid SQLite result for successful SELECT
  * queries, DB_OK for other successful queries. A DB error is
  * returned on failure.
  */
 function simpleQuery($query)
 {
     $ismanip = DB::isManip($query);
     $this->last_query = $query;
     $query = $this->_modifyQuery($query);
     ini_set('track_errors', true);
     $result = @sqlite_query($query, $this->connection);
     ini_restore('track_errors');
     $this->_lasterror = isset($php_errormsg) ? $php_errormsg : '';
     $this->result = $result;
     if (!$this->result) {
         return $this->sqliteRaiseError(null);
     }
     /* sqlite_query() seems to allways return a resource */
     /* so cant use that. Using $ismanip instead          */
     if (!$ismanip) {
         $numRows = $this->numRows($result);
         /* if numRows() returned PEAR_Error */
         if (is_object($numRows)) {
             return $numRows;
         }
         return $result;
     }
     return DB_OK;
 }
Beispiel #7
0
 /**
  * Prepares a query for multiple execution with execute().
  *
  * prepare() requires a generic query as string like <code>
  *    INSERT INTO numbers VALUES (?, ?, ?)
  * </code>.  The <kbd>?</kbd> characters are placeholders.
  *
  * Three types of placeholders can be used:
  *   + <kbd>?</kbd>  a quoted scalar value, i.e. strings, integers
  *   + <kbd>!</kbd>  value is inserted 'as is'
  *   + <kbd>&</kbd>  requires a file name.  The file's contents get
  *                     inserted into the query (i.e. saving binary
  *                     data in a db)
  *
  * Use backslashes to escape placeholder characters if you don't want
  * them to be interpreted as placeholders.  Example: <code>
  *    "UPDATE foo SET col=? WHERE col='over \& under'"
  * </code>
  *
  * @param string $query query to be prepared
  * @return mixed DB statement resource on success. DB_Error on failure.
  */
 function prepare($query)
 {
     $tokens = preg_split('/((?<!\\\\)[&?!])/', $query, -1, PREG_SPLIT_DELIM_CAPTURE);
     $token = 0;
     $types = array();
     $newquery = '';
     foreach ($tokens as $key => $val) {
         switch ($val) {
             case '?':
                 $types[$token++] = DB_PARAM_SCALAR;
                 break;
             case '&':
                 $types[$token++] = DB_PARAM_OPAQUE;
                 break;
             case '!':
                 $types[$token++] = DB_PARAM_MISC;
                 break;
             default:
                 $tokens[$key] = preg_replace('/\\\\([&?!])/', "\\1", $val);
                 $newquery .= $tokens[$key] . '?';
         }
     }
     $newquery = substr($newquery, 0, -1);
     $this->last_query = $query;
     $newquery = $this->modifyQuery($newquery);
     $stmt = @ibase_prepare($this->connection, $newquery);
     if ($stmt === false) {
         $stmt = $this->ibaseRaiseError();
     } else {
         $this->prepare_types[(int) $stmt] = $types;
         $this->manip_query[(int) $stmt] = DB::isManip($query);
     }
     return $stmt;
 }
Beispiel #8
0
<TABLE align=center cellSpacing=0 cellPadding=0 border=0>
<TBODY>
        <TR>
                <TD width=4 height=4><IMG height=4 src="images/corner.gif" width=4></TD>
        <TD align=left background=images/tb_top.gif height=4><IMG height=4 src="images/tb_left_topt.gif" width=8></TD>
        <TD align=right background=images/tb_top.gif height=4><IMG height=4 src="images/tb_right_topt.gif" width=8></TD>
        <TD width=4 height=4><IMG height=4 src="images/corner.gif" width=4></TD>
    </TR>
    <TR>
                <TD vAlign=top width=4 background=images/tb_left.gif height="50%"><IMG height=6 src="images/tb_left_topb.gif" width=3></TD>
                <TD colSpan=2 rowSpan=2>

<?php 
$sqlbox = "SELECT work_type, COUNT(*) AS Entries FROM xmec_user WHERE work_type <> '' GROUP BY work_type ORDER by Entries DESC";
$dbh =& XMEC::getDB();
if (DB::isManip($sqlbox)) {
    echo "No manipulation queries please !";
} else {
    $r = $dbh->query(XMEC_user::unQuote($sqlbox));
    if (DB::isError($r)) {
        echo "Query: {$sql} failed.";
    } else {
        echo "<table border=0>";
        echo "<tr bgcolor=#DDDDDD>";
        echo "<td><b class=title>Field of Work</b></td>";
        echo "<td><b class=title>XMECians</b></td>";
        echo "</tr>";
        while (is_array($x = $r->fetchRow())) {
            echo "<tr>";
            for ($i = 0; $i < count($x); $i++) {
                echo "<td bgcolor=#CFDDD1>{$x[$i]}</td>";
 /**
  * Determines the number of rows affected by a data maniuplation query
  *
  * 0 is returned for queries that don't manipulate data.
  *
  * @return int  the number of rows.  A DB_Error object on failure.
  */
 function affectedRows()
 {
     if (DB::isManip($this->last_query)) {
         return $this->affected;
     } else {
         return 0;
     }
 }
Beispiel #10
0
 /**
  * Prepares a query for multiple execution with execute().
  * @param $query query to be prepared
  *
  * @return DB statement resource
  */
 function prepare($query)
 {
     $tokens = split('[\\&\\?]', $query);
     $token = 0;
     $types = array();
     $qlen = strlen($query);
     for ($i = 0; $i < $qlen; $i++) {
         switch ($query[$i]) {
             case '?':
                 $types[$token++] = DB_PARAM_SCALAR;
                 break;
             case '&':
                 $types[$token++] = DB_PARAM_OPAQUE;
                 break;
         }
     }
     $newquery = strtr($query, '&', '?');
     $this->last_query = $query;
     $newquery = $this->modifyQuery($newquery);
     $stmt = ibase_prepare($this->connection, $newquery);
     $this->prepare_types[(int) $stmt] = $types;
     $this->manip_query[(int) $stmt] = DB::isManip($query);
     return $stmt;
 }
Beispiel #11
0
 function execute($stmt, $data = false)
 {
     $result = ibase_execute($stmt, $data);
     if (!$result) {
         return $this->raiseError();
     }
     if ($this->autocommit) {
         ibase_commit($this->connection);
     }
     return DB::isManip($this->manip_query[(int) $stmt]) ? DB_OK : new DB_result($this, $result);
 }
Beispiel #12
0
            }
            echo "<tr><td colspan=2 align=right><P><A href=aow.php class=link>...more</A></P></td><tr>";
            echo "</table>";
            echo "</td>";
        }
    }
    ?>
	</td>
	</TR>
	<TR>
	  	<TD width=225 valign=top bgcolor="#CEE3C1">
	<P BORDER=1><font color=#DE650C ><b>Current XMEC Poll</b></font></P>
<?php 
    $dbh =& XMEC::getDB();
    $sql = "SELECT title FROM poll_questions WHERE (" . "(start_date <= NOW()) AND " . "(end_date >= NOW()) )";
    if (DB::isManip($sql)) {
        echo "No manipulation queries please !";
    } else {
        $r = $dbh->query(XMEC_user::unQuote($sql));
        if (DB::isError($r)) {
            echo "Query: {$sql} failed.";
        } else {
            while (is_array($x = $r->fetchRow())) {
                for ($i = 0; $i < count($x); $i++) {
                    echo "<P><a href=polls.php class=flink>{$x[$i]}</a><BR></P>";
                }
            }
        }
        echo "</td>";
    }
    ?>
Beispiel #13
0
 public function _isManip($query)
 {
     return DB::isManip($query);
 }
Beispiel #14
0
 /**
  * Gets the number of rows affected by the data manipulation
  * query.  For other queries, this function returns 0.
  *
  * @return number of rows affected by the last query
  */
 function affectedRows()
 {
     if (DB::isManip($this->last_query)) {
         $result = $this->_affectedRows;
     } else {
         $result = 0;
     }
     return $result;
 }
Beispiel #15
0
 /**
  * Send a query to Informix and return the results as a
  * Informix resource identifier.
  *
  * @param $query the SQL query
  *
  * @return int returns a valid Informix result for successful SELECT
  * queries, DB_OK for other successful queries.  A DB error code
  * is returned on failure.
  */
 function simpleQuery($query)
 {
     $ismanip = DB::isManip($query);
     $this->last_query = $query;
     if (preg_match('/(SELECT)/i', $query)) {
         //TESTME: Use !DB::isManip()?
         // the scroll is needed for fetching absolute row numbers
         // in a select query result
         $result = @ifx_query($query, $this->connection, IFX_SCROLL);
     } else {
         if (!$this->autocommit && $ismanip) {
             if ($this->transaction_opcount == 0) {
                 $result = @ifx_query('BEGIN WORK', $this->connection);
                 if (!$result) {
                     return $this->ifxraiseError();
                 }
             }
             $this->transaction_opcount++;
         }
         $result = @ifx_query($query, $this->connection);
     }
     if (!$result) {
         return $this->ifxraiseError();
     }
     $this->affected = ifx_affected_rows($result);
     // Determine which queries that should return data, and which
     // should return an error code only.
     if (preg_match('/(SELECT)/i', $query)) {
         return $result;
     }
     // Result has to be freed even with a insert or update
     ifx_free_result($result);
     return DB_OK;
 }
Beispiel #16
0
 /**
  * MDB2_PEARProxy::modifyLimitQuery()
  */
 public function modifyLimitQuery($query, $from, $count, $params = array())
 {
     $is_manip = DB::isManip($query);
     $query = $this->db_object->_modifyQuery($query, $is_manip, $count, $from);
     return $query;
 }
Beispiel #17
0
 /**
  * Detect false errors messages from PEAR DB.
  *
  * The version of PEAR DB which ships with PHP 4.0.6 has a bug in that
  * it doesn't recognize "LOCK" and "UNLOCK" as SQL commands which don't
  * return any data.  (So when a "LOCK" command doesn't return any data,
  * DB reports it as an error, when in fact, it's not.)
  *
  * @access private
  * @return bool True iff error is not really an error.
  */
 function _is_false_error($error)
 {
     if ($error->getCode() != DB_ERROR) {
         return false;
     }
     $query = $this->_dbh->last_query;
     if (!preg_match('/^\\s*"?(INSERT|UPDATE|DELETE|REPLACE|CREATE' . '|DROP|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\\s/', $query)) {
         // Last query was not of the sort which doesn't return any data.
         //" <--kludge for brain-dead syntax coloring
         return false;
     }
     if (!in_array('ismanip', get_class_methods('DB'))) {
         // Pear shipped with PHP 4.0.4pl1 (and before, presumably)
         // does not have the DB::isManip method.
         return true;
     }
     if (DB::isManip($query)) {
         // If Pear thinks it's an isManip then it wouldn't have thrown
         // the error we're testing for....
         return false;
     }
     return true;
 }
Beispiel #18
0
 /**
  * Sends a query to the database server
  *
  * NOTICE:  This method needs PHP's track_errors ini setting to be on.
  * It is automatically turned on when connecting to the database.
  * Make sure your scripts don't turn it off.
  *
  * @param string  the SQL query string
  *
  * @return mixed  + a PHP result resrouce for successful SELECT queries
  *                + the DB_OK constant for other successful queries
  *                + a DB_Error object on failure
  */
 function simpleQuery($query)
 {
     $ismanip = DB::isManip($query);
     $this->last_query = $query;
     $query = $this->modifyQuery($query);
     $php_errormsg = '';
     $result = @sqlite_query($query, $this->connection);
     $this->_lasterror = $php_errormsg ? $php_errormsg : '';
     $this->result = $result;
     if (!$this->result) {
         return $this->sqliteRaiseError(null);
     }
     // sqlite_query() seems to allways return a resource
     // so cant use that. Using $ismanip instead
     if (!$ismanip) {
         $numRows = $this->numRows($result);
         if (is_object($numRows)) {
             // we've got PEAR_Error
             return $numRows;
         }
         return $result;
     }
     return DB_OK;
 }
Beispiel #19
0
 /**
  * Prepares a query for multiple execution with execute().
  *
  * With oci8, this is emulated.
  *
  * prepare() requires a generic query as string like <code>
  *    INSERT INTO numbers VALUES (?, ?, ?)
  * </code>.  The <kbd>?</kbd> characters are placeholders.
  *
  * Three types of placeholders can be used:
  *   + <kbd>?</kbd>  a quoted scalar value, i.e. strings, integers
  *   + <kbd>!</kbd>  value is inserted 'as is'
  *   + <kbd>&</kbd>  requires a file name.  The file's contents get
  *                     inserted into the query (i.e. saving binary
  *                     data in a db)
  *
  * Use backslashes to escape placeholder characters if you don't want
  * them to be interpreted as placeholders.  Example: <code>
  *    "UPDATE foo SET col=? WHERE col='over \& under'"
  * </code>
  *
  * @param string $query  the query to be prepared
  *
  * @return mixed  DB statement resource on success. DB_Error on failure.
  *
  * @see DB_oci8::execute()
  */
 function prepare($query)
 {
     $tokens = preg_split('/((?<!\\\\)[&?!])/', $query, -1, PREG_SPLIT_DELIM_CAPTURE);
     $binds = count($tokens) - 1;
     $token = 0;
     $types = array();
     $newquery = '';
     foreach ($tokens as $key => $val) {
         switch ($val) {
             case '?':
                 $types[$token++] = DB_PARAM_SCALAR;
                 unset($tokens[$key]);
                 break;
             case '&':
                 $types[$token++] = DB_PARAM_OPAQUE;
                 unset($tokens[$key]);
                 break;
             case '!':
                 $types[$token++] = DB_PARAM_MISC;
                 unset($tokens[$key]);
                 break;
             default:
                 $tokens[$key] = preg_replace('/\\\\([&?!])/', "\\1", $val);
                 if ($key != $binds) {
                     $newquery .= $tokens[$key] . ':bind' . $token;
                 } else {
                     $newquery .= $tokens[$key];
                 }
         }
     }
     $this->last_query = $query;
     $newquery = $this->modifyQuery($newquery);
     if (!($stmt = @OCIParse($this->connection, $newquery))) {
         return $this->oci8RaiseError();
     }
     $this->prepare_types[(int) $stmt] = $types;
     $this->manip_query[(int) $stmt] = DB::isManip($query);
     $this->_prepared_queries[(int) $stmt] = $newquery;
     return $stmt;
 }
Beispiel #20
0
                for ($i = 0; $i < count($x); $i++) {
                    echo "<P><a href=polls.php class=flink>{$x[$i]}</a><BR></P>";
                }
            }
        }
        echo "</td>";
    }
    ?>
	</td>
	 <TD width=5 ><img src="images/space.gif"></TD>
		<TD width=225 valign=top class=name bgcolor="#FBB3AA">
		<P ><font color=#574844><B>Latest Career Posting </B></font></P>
		<?php 
    $dbh =& XMEC::getDB();
    $sqle = "select company from job_posts  order by post_id desc limit 0,1;";
    if (DB::isManip($sqle)) {
        echo "No manipulation queries please !";
    } else {
        $r = $dbh->query(XMEC_user::unQuote($sqle));
        if (DB::isError($r)) {
            echo "Query: {$sqle} failed.";
        } else {
            while (is_array($x = $r->fetchRow())) {
                for ($i = 0; $i < count($x); $i++) {
                    echo "<P><a href=post_job.php class=flink>{$x[$i]}</A><BR></P>";
                }
            }
        }
        echo "</td>";
    }
    ?>
Beispiel #21
0
 /**
  * Gets the number of rows affected by the last query.
  * if the last query was a select, returns 0.
  *
  * @return number of rows affected by the last query or DB_ERROR
  */
 function affectedRows()
 {
     if (DB::isManip($this->last_query)) {
         $res = @mssql_query('select @@rowcount', $this->connection);
         if (!$res) {
             return $this->mssqlRaiseError();
         }
         $ar = @mssql_fetch_row($res);
         if (!$ar) {
             $result = 0;
         } else {
             @mssql_free_result($res);
             $result = $ar[0];
         }
     } else {
         $result = 0;
     }
     return $result;
 }
Beispiel #22
0
 /**
  * Sends a query to the database server
  *
  * @param string  the SQL query string
  *
  * @return mixed  + a PHP result resrouce for successful SELECT queries
  *                + the DB_OK constant for other successful queries
  *                + a DB_Error object on failure
  */
 function simpleQuery($query)
 {
     $ismanip = DB::isManip($query);
     $this->last_query = $query;
     $query = $this->modifyQuery($query);
     if (!$this->autocommit && $ismanip) {
         if ($this->transaction_opcount == 0) {
             $result = @pg_exec($this->connection, 'begin;');
             if (!$result) {
                 return $this->pgsqlRaiseError();
             }
         }
         $this->transaction_opcount++;
     }
     $result = @pg_exec($this->connection, $query);
     if (!$result) {
         return $this->pgsqlRaiseError();
     }
     /*
      * Determine whether queries produce affected rows, result or nothing.
      *
      * This logic was introduced in version 1.1 of the file by ssb,
      * though the regex has been modified slightly since then.
      *
      * PostgreSQL commands:
      * ABORT, ALTER, BEGIN, CLOSE, CLUSTER, COMMIT, COPY,
      * CREATE, DECLARE, DELETE, DROP TABLE, EXPLAIN, FETCH,
      * GRANT, INSERT, LISTEN, LOAD, LOCK, MOVE, NOTIFY, RESET,
      * REVOKE, ROLLBACK, SELECT, SELECT INTO, SET, SHOW,
      * UNLISTEN, UPDATE, VACUUM
      */
     if ($ismanip) {
         $this->affected = @pg_affected_rows($result);
         return DB_OK;
     } elseif (preg_match('/^\\s*\\(*\\s*(SELECT|EXPLAIN|FETCH|SHOW)\\s/si', $query)) {
         $this->row[(int) $result] = 0;
         // reset the row counter.
         $numrows = $this->numRows($result);
         if (is_object($numrows)) {
             return $numrows;
         }
         $this->_num_rows[(int) $result] = $numrows;
         $this->affected = 0;
         return $result;
     } else {
         $this->affected = 0;
         return DB_OK;
     }
 }
Beispiel #23
0
 /**
  * Adds LIMIT clauses to a query string according to current DBMS standards
  *
  * @param string $query   the query to modify
  * @param int    $from    the row to start to fetching (0 = the first row)
  * @param int    $count   the numbers of rows to fetch
  * @param mixed  $params  array, string or numeric data to be used in
  *                         execution of the statement.  Quantity of items
  *                         passed must match quantity of placeholders in
  *                         query:  meaning 1 placeholder for non-array
  *                         parameters or 1 placeholder per array element.
  *
  * @return string  the query string with LIMIT clauses added
  *
  * @access protected
  */
 function modifyLimitQuery($query, $from, $count, $params = array())
 {
     if (DB::isManip($query) || $this->_next_query_manip) {
         return preg_replace('/^([\\s(])*SELECT/i', "\\1SELECT TOP({$count})", $query);
     } else {
         return preg_replace('/([\\s(])*SELECT/i', "\\1SELECT TOP({$from}, {$count})", $query);
     }
 }
Beispiel #24
0
 /**
  * Prepares a query for multiple execution with execute().  With
  * oci8, this is emulated.
  * @param $query query to be prepared
  *
  * @return DB statement resource
  */
 function prepare($query)
 {
     $tokens = split('[\\&\\?]', $query);
     $token = 0;
     $types = array();
     for ($i = 0; $i < strlen($query); $i++) {
         switch ($query[$i]) {
             case '?':
                 $types[$token++] = DB_PARAM_SCALAR;
                 break;
             case '&':
                 $types[$token++] = DB_PARAM_OPAQUE;
                 break;
         }
     }
     $binds = sizeof($tokens) - 1;
     $newquery = '';
     for ($i = 0; $i < $binds; $i++) {
         $newquery .= $tokens[$i] . ":bind" . $i;
     }
     $newquery .= $tokens[$i];
     $this->last_query = $query;
     $newquery = $this->modifyQuery($newquery);
     $stmt = @OCIParse($this->connection, $newquery);
     $this->prepare_types[$stmt] = $types;
     $this->manip_query[(int) $stmt] = DB::isManip($query);
     return $stmt;
 }
Beispiel #25
0
 /**
  * Send a query to ODBC and return the results as a ODBC resource
  * identifier.
  *
  * @param $query the SQL query
  *
  * @return int returns a valid ODBC result for successful SELECT
  * queries, DB_OK for other successful queries.  A DB error code
  * is returned on failure.
  */
 function simpleQuery($query)
 {
     $this->last_query = $query;
     $query = $this->modifyQuery($query);
     $result = @odbc_exec($this->connection, $query);
     if (!$result) {
         return $this->odbcRaiseError();
         // XXX ERRORMSG
     }
     // Determine which queries that should return data, and which
     // should return an error code only.
     if (DB::isManip($query)) {
         $this->manip_result = $result;
         // For affectedRows()
         return DB_OK;
     }
     $this->row[(int) $result] = 0;
     $this->manip_result = 0;
     return $result;
 }
Beispiel #26
0
 /**
  * execute a SQL query.
  *
  * @param string $query  the SQL query 
  *
  * @return mixed + object DB_error object on failure
  *               + object Result resource for SELECT requests
  *               + bool TRUE for other sucessful requests
  */
 function simpleQuery($query)
 {
     $isManip = preg_match('/^\\s*"?(SELECT\\s+load_extension\\(|BEGIN[;\\s])/i', $query) || DB::isManip($query);
     $retryMicroseconds = 300000;
     $retryMore = 1.5;
     $retryNb = 10;
     for ($i = 0; $i <= $retryNb; $i++) {
         if ($isManip) {
             $this->result = sqlite3_exec($this->connection, $query);
         } else {
             $this->result = sqlite3_query($this->connection, $query);
         }
         if ($this->result) {
             return $this->result;
         }
         $errorNative = $this->errorNative();
         if ($errorNative == 'database is locked' && $i < $retryNb) {
             //error_log( 'SFN - database is locked, waiting ' . ( $retryMicroseconds / 1000 ) . ' ms and retrying...' );
             usleep($retryMicroseconds);
             $retryMicroseconds = floor($retryMicroseconds * $retryMore);
         } else {
             break;
         }
     }
     return $this->RaiseError($errorNative);
 }
 /**
  * Determines the number of rows affected by a data maniuplation query
  *
  * 0 is returned for queries that don't manipulate data.
  *
  * @return int  the number of rows.  A DB_Error object on failure.
  */
 function affectedRows()
 {
     if (DB::isManip($this->last_query)) {
         $result = @sybase_affected_rows($this->connection);
     } else {
         $result = 0;
     }
     return $result;
 }
Beispiel #28
0
 /**
  * query
  *
  * The query function runs 100% of all manipulation queries against the
  * master node. Additionally, DB_Virtual keeps track of transactions so if
  * you are in a transaction 100% of all transactions go to the master, 
  * including selects. Otherwise, it grabs a node and runs the query 
  * against that node.
  *
  * @access  public
  * @param   string  $query
  * @param   array   $params
  * @param   int     $mode
  * @see     DB::isManip(), DB_common::query()
  * @see     DB_Virtual::getNode()
  */
 public function query($query, $params = array(), $mode = DB_VIRTUAL_MASTER)
 {
     if (DB::isManip($query) || $this->masterOnly == true || $mode & DB_VIRTUAL_MASTER || $mode & DB_VIRTUAL_WRITE) {
         $node = $this->master;
     } else {
         $node = $this->getNode();
     }
     if ($mode & DB_VIRTUAL_CACHE) {
         trigger_error('You cannot use DB_VIRTUAL_CACHE in DB::query()', E_USER_NOTICE);
     }
     if ($mode & DB_VIRTUAL_MASTER) {
         return $this->queryMaster($query, $params);
     }
     $this->lastNode = $node;
     $result = $this->nodes[$node]->query($query, $params);
     if ($node != $this->master && !PEAR::isError($result) && $result->numRows() == 0) {
         $result = $this->nodes[$this->master]->query($query, $params);
     }
     return $result;
 }
Beispiel #29
0
 /**
  * Checks if the given query is a manipulation query. This also takes into
  * account the _next_query_manip flag and sets the _last_query_manip flag
  * (and resets _next_query_manip) according to the result.
  *
  * @param string The query to check.
  *
  * @return boolean true if the query is a manipulation query, false
  * otherwise
  *
  * @access protected
  */
 function _checkManip($query)
 {
     if ($this->_next_query_manip || DB::isManip($query)) {
         $this->_last_query_manip = true;
     } else {
         $this->_last_query_manip = false;
     }
     $this->_next_query_manip = false;
     return $this->_last_query_manip;
     $manip = $this->_next_query_manip;
 }
Beispiel #30
0
 /**
  * execute a SQL query.
  *
  * @param string $query  the SQL query 
  *
  * @return mixed + object DB_error object on failure
  *               + object Result resource for SELECT requests
  *               + bool TRUE for other sucessful requests
  */
 function simpleQuery($query)
 {
     $isManip = DB::isManip($query);
     if ($isManip) {
         $this->result = sqlite3_exec($this->connection, $query);
     } else {
         $this->result = sqlite3_query($this->connection, $query);
     }
     if (!$this->result) {
         return $this->RaiseError($this->errorNative());
     }
     return $this->result;
 }