Version 4.1.2
This commit is contained in:
1 parent
3ba79295ee
commit
28bd025b35
1131 files changed
+63658
-20579
No files matched your search
+28
-62
@@ -256,41 +256,33 @@ class _Db extends \mysqli
|
||||
/* Sort out subqueries */
|
||||
$binds = array();
|
||||
$i = 0;
|
||||
foreach ( $_binds as $bindVal )
|
||||
for ( $j = 0; $j < mb_strlen( $query ); $j++ )
|
||||
{
|
||||
$i++;
|
||||
if ( $bindVal instanceof \IPS\Db\Select )
|
||||
if ( $query[ $j ] == '?' )
|
||||
{
|
||||
$pos = 0;
|
||||
for ( $j=0; $j<$i; $j++ )
|
||||
if ( $_binds[ $i ] instanceof \IPS\Db\Select )
|
||||
{
|
||||
$pos = mb_strpos( $query, '?', $pos ) + 1;
|
||||
$query = mb_substr( $query, 0, $j ) . $_binds[ $i ]->query . mb_substr( $query, $j + 1);
|
||||
$j += mb_strlen( $_binds[ $i ]->query );
|
||||
|
||||
foreach ( $_binds[ $i ]->binds as $_bind )
|
||||
{
|
||||
$binds[] = $_bind;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$binds[] = $_binds[ $i ];
|
||||
}
|
||||
$query = mb_substr( $query, 0, $pos - 1 ) . $bindVal->query . mb_substr( $query, $pos );
|
||||
$i--;
|
||||
|
||||
foreach ( $bindVal->binds as $v )
|
||||
{
|
||||
$binds[] = $v;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$binds[] = $bindVal;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Loop values to bind */
|
||||
$i = 0;
|
||||
$longThreshold = 1048576;
|
||||
$sendAsLong = array();
|
||||
foreach ( $binds as $bindVal )
|
||||
{
|
||||
if( ( is_object( $bindVal ) OR is_string( $bindVal ) ) AND \strlen( (string) $bindVal ) > $longThreshold )
|
||||
{
|
||||
$sendAsLong[ $i ] = (string) $bindVal;
|
||||
}
|
||||
|
||||
$i++;
|
||||
switch ( gettype( $bindVal ) )
|
||||
{
|
||||
@@ -304,27 +296,13 @@ class _Db extends \mysqli
|
||||
break;
|
||||
|
||||
case 'string':
|
||||
if( \strlen( $bindVal ) > $longThreshold )
|
||||
{
|
||||
$bind->add( 'b', NULL );
|
||||
}
|
||||
else
|
||||
{
|
||||
$bind->add( 's', $bindVal );
|
||||
}
|
||||
$bind->add( 's', $bindVal );
|
||||
break;
|
||||
|
||||
case 'object':
|
||||
if( method_exists( $bindVal, '__toString' ) )
|
||||
{
|
||||
if( \strlen( $bindVal ) > $longThreshold )
|
||||
{
|
||||
$bind->add( 'b', NULL );
|
||||
}
|
||||
else
|
||||
{
|
||||
$bind->add( 's', (string) $bindVal );
|
||||
}
|
||||
$bind->add( 's', (string) $bindVal );
|
||||
break;
|
||||
}
|
||||
// Deliberately no break
|
||||
@@ -370,7 +348,7 @@ class _Db extends \mysqli
|
||||
$line = $b['line'];
|
||||
}
|
||||
|
||||
if( isset( $b['class'] ) and $b['class'] !== 'IPS\_Db' and $b['class'] !== 'IPS\Db\_Select' )
|
||||
if( isset( $b['class'] ) and !in_array( $b['class'], array( 'IPS\_Db', 'IPS\Db\_Select', 'IPS\Patterns\_ActiveRecord', 'IPS\Patterns\_ActiveRecordIterator' ) ) )
|
||||
{
|
||||
$comment = "{$b['class']}::{$b['function']}:{$line}";
|
||||
break;
|
||||
@@ -378,31 +356,18 @@ class _Db extends \mysqli
|
||||
}
|
||||
$_query = $query;
|
||||
$query = "/*{$comment}*/ {$query}";
|
||||
|
||||
|
||||
/* Prepare */
|
||||
$stmt = parent::prepare( $query );
|
||||
if( $stmt === FALSE )
|
||||
{
|
||||
throw new \IPS\Db\Exception( $this->error, $this->errno, NULL, $_query, $binds );
|
||||
}
|
||||
|
||||
|
||||
/* Bind values */
|
||||
if( $bind->haveBinds() === TRUE )
|
||||
{
|
||||
call_user_func_array( array( $stmt, 'bind_param' ), $bind->get() );
|
||||
|
||||
if( count( $sendAsLong ) )
|
||||
{
|
||||
foreach( $sendAsLong as $index => $data )
|
||||
{
|
||||
$chunks = str_split( $data, $longThreshold - 1 );
|
||||
|
||||
foreach( $chunks as $chunk )
|
||||
{
|
||||
$stmt->send_long_data( $index, $chunk );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Execute */
|
||||
@@ -650,15 +615,16 @@ class _Db extends \mysqli
|
||||
}
|
||||
|
||||
/**
|
||||
* Run REPLACE statament and return number of affected rows
|
||||
* Run REPLACE statament and return number of affected rows OR inserted ID
|
||||
*
|
||||
* @see <a href='http://dev.mysql.com/doc/refman/5.1/en/replace.html'>REPLACE Syntax</a>
|
||||
* @param string $table Table name
|
||||
* @param array $set Values to insert
|
||||
* @return \IPS\Db\Statement
|
||||
* @param string $table Table name
|
||||
* @param array $set Values to insert
|
||||
* @param bool $getInsertId If TRUE, returns the insert ID rather than the number of affected rows
|
||||
* @return int
|
||||
* @throws \IPS\Db\Exception
|
||||
*/
|
||||
public function replace( $table, $set )
|
||||
public function replace( $table, $set, $getInsertId=false )
|
||||
{
|
||||
/* Build */
|
||||
$query = $this->_buildInsertQuery( 'REPLACE', $table, $set );
|
||||
@@ -672,7 +638,7 @@ class _Db extends \mysqli
|
||||
return $stmt;
|
||||
}
|
||||
|
||||
return $stmt->affected_rows;
|
||||
return $getInsertId ? $stmt->insert_id : $stmt->affected_rows;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user