Exemple #1
0
function bmark_query($sql, $dbh)
{
    $result_set = null;
    if (is_a($dbh, "DrizzleCon")) {
        $sql = str_replace("ENGINE=InnoDB DEFAULT CHARSET=utf8", "", $sql);
        $result = @drizzle_query($dbh, $sql) or die('ERROR: ' . drizzle_con_error($dbh) . "\n");
        // buffer result set
        drizzle_result_buffer($result) or die('ERROR: ' . drizzle_con_error($dbh) . "\n");
        if (drizzle_result_row_count($result)) {
            while ($row = drizzle_row_next($result)) {
                $result_set[] = $row;
            }
        }
        // free result set
        drizzle_result_free($result);
        // close connection
        // drizzle_con_close($dbh);
        return $result_set;
    }
    if (bmark_type($dbh) === 'mysql') {
        $result = mysql_query($sql, $dbh) or die('ERROR: ' . mysql_error($dbh));
        if (preg_match("/select.*/i", $sql)) {
            if (mysql_num_rows($result) > 0) {
                while ($row = mysql_fetch_assoc($result)) {
                    $result_set[] = $row;
                }
            }
        }
        return $result_set;
    }
    return FALSE;
}
Exemple #2
0
 /**
  * This function initializes the class.
  *
  * @access public
  * @override
  * @param DB_Connection_Driver $connection  the connection to be used
  * @param string $sql                       the SQL statement to be queried
  * @param integer $mode                     the execution mode to be used
  */
 public function __construct(DB_Connection_Driver $connection, $sql, $mode = NULL)
 {
     $resource = $connection->get_resource();
     $command = @drizzle_query($resource, $sql);
     if ($command === FALSE or !@drizzle_result_buffer($command)) {
         throw new Throwable_SQL_Exception('Message: Failed to query SQL statement. Reason: :reason', array(':reason' => @drizzle_con_error($resource)));
     }
     $this->command = $command;
     $this->record = FALSE;
 }
Exemple #3
0
 function find($table_type, $field, $value, $like = '', $partition_flag = '')
 {
     // drizzle
     if (strcmp($this->database_type, 'drizzle') == 0) {
         if (strcmp($like, 'like') == 0) {
             $like = 'like';
             $value = "'%{$value}'";
         } else {
             $like = '=';
         }
         if (strcmp($partition_flag, 'nopart') == 0) {
             $sql = "select * from {$table_type}" . "_no_partition where {$field} {$like} '{$value}'";
             $result = @drizzle_query($this->connection, $sql);
             if (!$result) {
                 die('Invalid query: ' . drizzle_con_error($this->connection));
             }
             drizzle_result_buffer($result) or die('ERROR: ' . drizzle_con_error($dbh) . "\n");
             while ($row = drizzle_row_next($result)) {
                 $myarray[] = $row;
             }
             return $myarray;
         }
         if (strcmp($partition_flag, 'drizzle') == 0) {
             $sql = "select * from {$table_type} where {$field} {$like} '{$value}'";
             print "partition sql: {$sql}\n";
             $result = @drizzle_query($this->connection, $sql);
             if (!$result) {
                 die('Invalid query: ' . drizzle_con_error($this->connection));
             }
             drizzle_result_buffer($result) or die('ERROR: ' . drizzle_con_error($dbh) . "\n");
             while ($row = drizzle_row_next($result)) {
                 $myarray[] = $row;
             }
             return $myarray;
         }
         // iterate through the tables using the meta_table
         $sql = "select * from meta_table where tablename like \"" . $table_type . "%\"";
         print $sql . "\n";
         try {
             $result = @drizzle_query($this->connection, $sql);
             if (!$result) {
                 throw new Exception('meta_table query failed');
             }
         } catch (Exception $e) {
             echo drizzle_con_error($this->connection) . "\n";
             echo "Caught active server error exception:\n", $e->getMessage(), " ", $e->getFile(), ": Line ", $e->getLine(), "\n", $e->getTraceAsString(), "\n";
         }
         drizzle_result_buffer($result) or die('ERROR: ' . drizzle_con_error($dbh) . "\n");
         while ($row = drizzle_row_next($result)) {
             print_r($row);
             $current_table = $row[1];
             $iterator = $row[2];
             $last_user_id = $row[3];
         }
         print "current_table: {$current_table}\n";
         // awesome, we got meta data
         // we need to now:
         // go through each table
         // find the info
         // return the info
         // get current_table number
         preg_match('/_[0-9]+/', $current_table, $matches);
         $bar_number = $matches[0];
         preg_match('/[0-9]+/', $bar_number, $matches);
         $table_number = $matches[0];
         // get how long the number is b/c of padding issues later
         $num_length = strlen($table_number);
         $i_table_number = (int) $table_number;
         // for ($i = 0; $i <= $i_table_number; $i++) {
         $i = 0;
         $i_sent = 0;
         $myarray = array();
         while ($i_sent <= 0) {
             // search each partition
             $curr_table = $table_type . "_" . padNumber($i, $num_length);
             $sql = "select * from {$curr_table} where {$field} {$like} '{$value}'";
             print $sql . "\n";
             $result = @drizzle_query($this->connection, $sql);
             if (!$result) {
                 die('Invalid query: ' . drizzle_con_error($this->connection));
             }
             drizzle_result_buffer($result) or die('ERROR: ' . drizzle_con_error($dbh) . "\n");
             while ($row = drizzle_row_next($result)) {
                 $myarray[] = $row;
             }
             print "count (myarray) : " . count($myarray) . "\n";
             if (count($myarray) >= 1) {
                 print "count > 1\n";
                 $i_sent = 1;
             }
             if ($i >= $i_table_number) {
                 print "{$i} <= {$i_table_number}\n";
                 $i_sent = 1;
             }
             $i++;
         }
         /*
         			$sql = "select * from $table where $field $like $value";
         			$result = mysql_query($sql, $this->connection);
         			if (!$result) {
         				die('Invalid query: ' . mysql_error());
         			}
         			while($row = mysql_fetch_assoc($result))
         			{
         			  $array[] = $row; 
         			}
         */
         print_r($myarray);
         return $myarray;
     }
     // end of drizzle portion
     // mysql
     if (strcmp($this->database_type, 'mysql') == 0) {
         if (strcmp($like, 'like') == 0) {
             $like = 'like';
             $value = "'%{$value}'";
         } else {
             $like = '=';
         }
         if (strcmp($partition_flag, 'nopart') == 0) {
             $sql = "select SQL_CACHE * from {$table_type}" . "_no_partition where {$field} {$like} '{$value}'";
             $result = mysql_query($sql, $this->connection);
             if (!$result) {
                 die('Invalid query: ' . mysql_error());
             }
             while ($row = mysql_fetch_assoc($result)) {
                 $myarray[] = $row;
             }
             return $myarray;
         }
         if (strcmp($partition_flag, 'mysql') == 0) {
             $sql = "select SQL_CACHE * from {$table_type} where {$field} {$like} '{$value}'";
             print "partition sql: {$sql}\n";
             $result = mysql_query($sql, $this->connection);
             if (!$result) {
                 die('Invalid query: ' . mysql_error());
             }
             while ($row = mysql_fetch_assoc($result)) {
                 $myarray[] = $row;
             }
             return $myarray;
         }
         // iterate through the tables using the meta_table
         $sql = "select SQL_CACHE * from meta_table where tablename like \"" . $table_type . "%\"";
         print $sql . "\n";
         $result = mysql_query($sql, $this->connection);
         if (!$result) {
             die('Cannnot access meta table: ' . mysql_error());
         }
         while ($row = mysql_fetch_assoc($result)) {
             $current_table = $row['tablename'];
             $iterator = $row['iterator'];
             $last_user_id = $row['last_user_id'];
         }
         print "current_table: {$current_table}\n";
         // awesome, we got meta data
         // we need to now:
         // go through each table
         // find the info
         // return the info
         // get current_table number
         preg_match('/_[0-9]+/', $current_table, $matches);
         $bar_number = $matches[0];
         preg_match('/[0-9]+/', $bar_number, $matches);
         $table_number = $matches[0];
         // get how long the number is b/c of padding issues later
         $num_length = strlen($table_number);
         $i_table_number = (int) $table_number;
         // for ($i = 0; $i <= $i_table_number; $i++) {
         $i = 0;
         $i_sent = 0;
         $myarray = array();
         while ($i_sent <= 0) {
             // search each partition
             $curr_table = $table_type . "_" . padNumber($i, $num_length);
             $sql = "select SQL_CACHE * from {$curr_table} where {$field} {$like} '{$value}'";
             print $sql . "\n";
             $result = mysql_query($sql, $this->connection);
             if (!$result) {
                 die('Invalid query: ' . mysql_error());
             }
             while ($row = mysql_fetch_assoc($result)) {
                 $myarray[] = $row;
             }
             print "count (myarray) : " . count($myarray) . "\n";
             if (count($myarray) >= 1) {
                 print "count > 1\n";
                 $i_sent = 1;
             }
             if ($i >= $i_table_number) {
                 print "{$i} <= {$i_table_number}\n";
                 $i_sent = 1;
             }
             $i++;
         }
         /*
         			$sql = "select * from $table where $field $like $value";
         			$result = mysql_query($sql, $this->connection);
         			if (!$result) {
         				die('Invalid query: ' . mysql_error());
         			}
         			while($row = mysql_fetch_assoc($result))
         			{
         			  $array[] = $row; 
         			}
         */
         print_r($myarray);
         return $myarray;
     }
     // end of mysql portion
 }