function _query($sql, $iarr = false) { if (!$this->isConnected()) { return false; } if (!$this->autoCommit && $this->_transactionID) { $conn = $this->_transactionID; $docommit = false; } else { $conn = $this->_connectionID; $docommit = true; } if (is_array($sql)) { $fn = 'fbird_execute'; $sql = $sql[1]; if (is_array($iarr)) { if (ADODB_PHPVER >= 0x4050) { // actually 4.0.4 if (!isset($iarr[0])) { $iarr[0] = ''; } // PHP5 compat hack $fnarr = array_merge(array($sql), $iarr); $ret = call_user_func_array($fn, $fnarr); } else { switch (sizeof($iarr)) { case 1: $ret = $fn($sql, $iarr[0]); break; case 2: $ret = $fn($sql, $iarr[0], $iarr[1]); break; case 3: $ret = $fn($sql, $iarr[0], $iarr[1], $iarr[2]); break; case 4: $ret = $fn($sql, $iarr[0], $iarr[1], $iarr[2], $iarr[3]); break; case 5: $ret = $fn($sql, $iarr[0], $iarr[1], $iarr[2], $iarr[3], $iarr[4]); break; case 6: $ret = $fn($sql, $iarr[0], $iarr[1], $iarr[2], $iarr[3], $iarr[4], $iarr[5]); break; case 7: $ret = $fn($sql, $iarr[0], $iarr[1], $iarr[2], $iarr[3], $iarr[4], $iarr[5], $iarr[6]); break; default: ADOConnection::outp("Too many parameters to ibase query {$sql}"); case 8: $ret = $fn($sql, $iarr[0], $iarr[1], $iarr[2], $iarr[3], $iarr[4], $iarr[5], $iarr[6], $iarr[7]); break; } } } else { $ret = $fn($sql); } } else { $fn = 'fbird_query'; if (is_array($iarr)) { if (ADODB_PHPVER >= 0x4050) { // actually 4.0.4 if (sizeof($iarr) == 0) { $iarr[0] = ''; } // PHP5 compat hack $fnarr = array_merge(array($conn, $sql), $iarr); $ret = call_user_func_array($fn, $fnarr); } else { switch (sizeof($iarr)) { case 1: $ret = $fn($conn, $sql, $iarr[0]); break; case 2: $ret = $fn($conn, $sql, $iarr[0], $iarr[1]); break; case 3: $ret = $fn($conn, $sql, $iarr[0], $iarr[1], $iarr[2]); break; case 4: $ret = $fn($conn, $sql, $iarr[0], $iarr[1], $iarr[2], $iarr[3]); break; case 5: $ret = $fn($conn, $sql, $iarr[0], $iarr[1], $iarr[2], $iarr[3], $iarr[4]); break; case 6: $ret = $fn($conn, $sql, $iarr[0], $iarr[1], $iarr[2], $iarr[3], $iarr[4], $iarr[5]); break; case 7: $ret = $fn($conn, $sql, $iarr[0], $iarr[1], $iarr[2], $iarr[3], $iarr[4], $iarr[5], $iarr[6]); break; default: ADOConnection::outp("Too many parameters to ibase query {$sql}"); case 8: $ret = $fn($conn, $sql, $iarr[0], $iarr[1], $iarr[2], $iarr[3], $iarr[4], $iarr[5], $iarr[6], $iarr[7]); break; } } } else { $ret = $fn($conn, $sql); } } if ($docommit && $ret === true) { fbird_commit($this->_connectionID); } $this->_handleerror(); return $ret; }
function export_data($export) { global $s_fields, $warning; ini_set('ibase.dateformat', $export['general']['date']); ini_set('ibase.timeformat', $export['general']['time']); ini_set('ibase.timestampformat', $export['general']['date'] . ' ' . $export['general']['time']); if ($export['format'] == 'sql' && $export['sql']['info']) { echo sql_export_info($export, replace_escape_sequences($export['sql']['lineend'])); } foreach (export_queries($export) as $query) { if (DEBUG) { add_debug($query, __FILE__, __LINE__); } $trans = fbird_trans(TRANS_READ, $dbhandle); $res = @fbird_query($trans, $query); if ($res === FALSE) { $ib_error = fbird_errmsg(); $warning = ''; return FALSE; } $columns = $col_types = $num_fields = array(); $num = fbird_num_fields($res); for ($idx = 0; $idx < $num; $idx++) { $info = fbird_field_info($res, $idx); $columns[] = $info['name']; $col_types[] = $info['type']; $num_fields[] = is_number_type(substr($info['type'], 0, strcspn($info['type'], '('))); } $tablename = $info['relation']; $export['query'] = array('source' => $query, 'columns' => $columns, 'col_types' => $col_types, 'num_fields' => $num_fields, 'result' => $res); switch ($export['format']) { case 'csv': export_csv_data($export); break; case 'sql': export_sql_data($export, $tablename); break; case 'ext': printf('Export data to %s is still not implemented!', $export['format']); break; default: echo 'Unsupported export format!'; } fbird_free_result($res); fbird_commit($trans); } }
function get_indices($order, $dir) { global $dbhandle; $order_field = $order == 'name' ? 'I.RDB$INDEX_NAME' : 'I.RDB$RELATION_NAME'; $sql = 'SELECT I.RDB$INDEX_NAME AS INAME, ' . 'I.RDB$RELATION_NAME AS RNAME, ' . 'I.RDB$UNIQUE_FLAG AS UFLAG, ' . 'I.RDB$INDEX_INACTIVE AS IFLAG, ' . 'I.RDB$INDEX_TYPE AS ITYPE, ' . 'S.RDB$FIELD_NAME AS FNAME, ' . 'S.RDB$FIELD_POSITION AS POS ' . 'FROM RDB$INDICES I ' . 'JOIN RDB$INDEX_SEGMENTS S ' . 'ON S.RDB$INDEX_NAME=I.RDB$INDEX_NAME ' . 'WHERE (I.RDB$SYSTEM_FLAG IS NULL OR I.RDB$SYSTEM_FLAG=0)' . 'AND I.RDB$FOREIGN_KEY IS NULL ' . "AND I.RDB\$INDEX_NAME NOT STARTING WITH 'RDB\$' " . 'ORDER BY ' . $order_field . ' ' . $dir; $trans = fbird_trans(TRANS_READ, $dbhandle); $res = fbird_query($trans, $sql) or ib_error(); $indices = array(); while ($obj = fbird_fetch_object($res)) { if (!isset($indices[$obj->INAME])) { $iname = trim($obj->INAME); $indices[$iname]['table'] = trim($obj->RNAME); $indices[$iname]['dir'] = isset($obj->ITYPE) && $obj->ITYPE == 1 ? 'DESC' : 'ASC'; $indices[$iname]['uniq'] = isset($obj->UFLAG) ? TRUE : FALSE; $indices[$iname]['active'] = isset($obj->IFLAG) && $obj->IFLAG == 1 ? FALSE : TRUE; $indices[$iname]['pos'] = $obj->POS; } $indices[$iname]['seg'][$obj->POS] = trim($obj->FNAME); } fbird_commit($trans); return $indices; }
if ($s_sql_panels[$idx][2] == 'open') { // if the query have result rows if (is_resource($res) && @fbird_num_fields($res) > 0) { $fieldinfo[$lnr] = get_field_info($res); // save the rows for the output in the sql_output panel while ($row = fbird_fetch_object($res)) { $results[$lnr][] = get_object_vars($row); $cnt++; if ($cnt >= SHOW_OUTPUT_ROWS && !isset($_POST['sql_display_all'])) { $s_sql['more'] = TRUE; break; } } } } fbird_commit($trans); } if (!empty($results)) { $js_stack .= js_markable_table(); } } // cleanup the watchtable output buffer $s_watch_buffer = ''; } // // process the export buttons from the sql_enter panel // if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST)) { foreach (array_keys($_POST) as $name) { if (preg_match('/sql_export_([0-9]+)/', $name, $matches) && isset($s_sql['queries'][$matches[1]])) { // set export parameters
function get_column_fk_defs($cname, $iname) { global $dbhandle; $defs = array('fk_name' => $cname); $trans = fbird_trans(TRANS_READ, $dbhandle); $sql = 'SELECT RDB$UPDATE_RULE,' . ' RDB$DELETE_RULE' . ' FROM RDB$REF_CONSTRAINTS' . " WHERE RDB\$CONSTRAINT_NAME='" . $cname . "'"; $res = @fbird_query($trans, $sql) or ib_error(__FILE__, __LINE__, $sql); if ($res && ($row = fbird_fetch_row($res))) { fbird_free_result($res); } $defs['on_update'] = trim($row[0]); $defs['on_delete'] = trim($row[1]); $sql = 'SELECT I2.RDB$RELATION_NAME,' . ' SE.RDB$FIELD_NAME' . ' FROM RDB$INDICES I1' . ' INNER JOIN RDB$INDICES I2 ON I1.RDB$FOREIGN_KEY=I2.RDB$INDEX_NAME' . ' INNER JOIN RDB$INDEX_SEGMENTS SE ON I2.RDB$INDEX_NAME=SE.RDB$INDEX_NAME' . " WHERE I1.RDB\$INDEX_NAME='" . $iname . "'"; $res = @fbird_query($trans, $sql) or ib_error(__FILE__, __LINE__, $sql); if ($res && ($row = fbird_fetch_row($res))) { fbird_free_result($res); } $defs['fk_table'] = trim($row[0]); $defs['fk_column'] = trim($row[1]); fbird_commit($trans); return $defs; }