/**
* Prepare & execute an SQL statement, quoting and inserting arguments
* in the appropriate places.
- * @param
+ * @param string $query
+ * @param string $args (default null)
*/
function safeQuery( $query, $args = null ) {
$prepared = $this->prepare( $query, 'Database::safeQuery' );
* The value inserted should be fetched from nextSequenceValue()
*
* Example:
- * $id = $dbw->nextSequenceValue('cur_cur_id_seq');
- * $dbw->insert('cur',array('cur_id' => $id));
+ * $id = $dbw->nextSequenceValue('page_page_id_seq');
+ * $dbw->insert('page',array('page_id' => $id));
* $id = $dbw->insertId();
*/
function insertId() { return mysql_insert_id( $this->mConn ); }
* Get the last error number
* See mysql_errno()
*/
- function lastErrno() { return mysql_errno(); }
+ function lastErrno() {
+ if ( $this->mConn ) {
+ return mysql_errno( $this->mConn );
+ } else {
+ return mysql_errno();
+ }
+ }
/**
* Get a description of the last error
* See mysql_error() for more details
*/
- function lastError() { return mysql_error(); }
-
+ function lastError() {
+ if ( $this->mConn ) {
+ $error = mysql_error( $this->mConn );
+ } else {
+ $error = mysql_error();
+ }
+ if( $error ) {
+ $error .= ' (' . $this->mServer . ')';
+ }
+ return $error;
+ }
/**
* Get the number of rows affected by the last write query
* See mysql_affected_rows() for more details
* $varMap must be an associative array of the form array( 'dest1' => 'source1', ...)
* Source items may be literals rather than field names, but strings should be quoted with Database::addQuotes()
* $conds may be "*" to copy the whole table
+ * srcTable may be an array of tables.
*/
function insertSelect( $destTable, $srcTable, $varMap, $conds, $fname = 'Database::insertSelect' ) {
$destTable = $this->tableName( $destTable );
- $srcTable = $this->tableName( $srcTable );
+ if( is_array( $srcTable ) ) {
+ $srcTable = implode( ',', array_map( array( &$this, 'tableName' ), $srcTable ) );
+ } else {
+ $srcTable = $this->tableName( $srcTable );
+ }
$sql = "INSERT INTO $destTable (" . implode( ',', array_keys( $varMap ) ) . ')' .
' SELECT ' . implode( ',', $varMap ) .
" FROM $srcTable";
$this->query( 'BEGIN', $myFname );
$args = func_get_args();
$function = array_shift( $args );
- $oldIgnore = $dbw->ignoreErrors( true );
+ $oldIgnore = $this->ignoreErrors( true );
$tries = DEADLOCK_TRIES;
if ( is_array( $function ) ) {
$fname = $function[0];
$sql = $this->lastQuery();
if ( $errno ) {
- if ( $dbw->wasDeadlock() ) {
+ if ( $this->wasDeadlock() ) {
# Retry
usleep( mt_rand( DEADLOCK_DELAY_MIN, DEADLOCK_DELAY_MAX ) );
} else {
- $dbw->reportQueryError( $error, $errno, $sql, $fname );
+ $this->reportQueryError( $error, $errno, $sql, $fname );
}
}
- } while( $dbw->wasDeadlock && --$tries > 0 );
+ } while( $this->wasDeadlock() && --$tries > 0 );
$this->ignoreErrors( $oldIgnore );
if ( $tries <= 0 ) {
$this->query( 'ROLLBACK', $myFname );