Exemplo n.º 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;
}
Exemplo n.º 2
0
 /**
  * This function advances the reader to the next record.
  *
  * @access public
  * @override
  * @return boolean                          whether another record was fetched
  */
 public function read()
 {
     $this->record = @drizzle_row_next($this->command);
     return $this->record !== FALSE;
 }
Exemplo n.º 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
 }