function get_fk_lookups_data($tablename, $fk_lookups)
{
    $lookups_data = array();
    $fk_defs = get_foreignkeys($tablename, 'S');
    foreach ($fk_defs as $colname => $defs) {
        // skip foreign keys with more than FKLOOKUP_ENTRIES values
        if (!isset($GLOBALS['s_tables'][$defs['table']]['count'])) {
            $GLOBALS['s_tables'][$defs['table']]['count'] = get_table_count($defs['table']);
        }
        if ($GLOBALS['s_tables'][$defs['table']]['count'] > FKLOOKUP_ENTRIES) {
            continue;
        }
        $value_field = ifsetor($fk_lookups[$colname], $defs['column']);
        if ($value_field != $defs['column']) {
            $value_field = "COALESCE(" . $value_field . ", '')" . " || ' - '" . ' || ' . $defs['column'];
        }
        $sql = 'SELECT ' . $defs['column'] . ', ' . $value_field . ' FROM ' . $defs['table'] . ' ORDER BY ' . $value_field . ' ASC';
        $res = fbird_query($GLOBALS['dbhandle'], $sql) or ib_error(__FILE__, __LINE__, $sql);
        $data = array();
        while ($row = fbird_fetch_row($res)) {
            $data[trim($row[0])] = trim($row[1]);
        }
        fbird_free_result($res);
        $lookups_data[$colname] = array('table' => $defs['table'], 'column' => $defs['column'], 'data' => $data);
    }
    return $lookups_data;
}
Пример #2
0
 function _fetch()
 {
     $f = @fbird_fetch_row($this->_queryID);
     if ($f === false) {
         $this->fields = false;
         return false;
     }
     // OPN stuff start - optimized
     // fix missing nulls and decode blobs automatically
     global $ADODB_ANSI_PADDING_OFF;
     //$ADODB_ANSI_PADDING_OFF=1;
     $rtrim = !empty($ADODB_ANSI_PADDING_OFF);
     for ($i = 0, $max = $this->_numOfFields; $i < $max; $i++) {
         if ($this->_cacheType[$i] == "BLOB") {
             if (isset($f[$i])) {
                 $f[$i] = $this->connection->_BlobDecode($f[$i]);
             } else {
                 $f[$i] = null;
             }
         } else {
             if (!isset($f[$i])) {
                 $f[$i] = null;
             } else {
                 if ($rtrim && is_string($f[$i])) {
                     $f[$i] = rtrim($f[$i]);
                 }
             }
         }
     }
     // OPN stuff end
     $this->fields = $f;
     if ($this->fetchMode == ADODB_FETCH_ASSOC) {
         $this->fields = $this->GetRowAssoc(ADODB_ASSOC_CASE);
     } else {
         if ($this->fetchMode == ADODB_FETCH_BOTH) {
             $this->fields = array_merge($this->fields, $this->GetRowAssoc(ADODB_ASSOC_CASE));
         }
     }
     return true;
 }
function get_table_count($tablename)
{
    $quote = identifier_quote($GLOBALS['s_login']['dialect']);
    $sql = 'SELECT COUNT(*) AS CNT FROM ' . $quote . $tablename . $quote;
    $res = fbird_query($GLOBALS['dbhandle'], $sql) or $ib_error .= fbird_errmsg() . "<br>\n";
    $count = FALSE;
    if (is_resource($res)) {
        $row = fbird_fetch_row($res);
        $count = $row[0];
        fbird_free_result($res);
    }
    return $count;
}
Пример #4
0
function export_sql_data($export, $table)
{
    global $ib_error, $warning, $dbhandle;
    $line_ending = replace_escape_sequences($export['sql']['lineend']);
    $replace_null = $export['general']['replnull'];
    $target_table = export_replace_placeholders($export['sql']['ttable'], $GLOBALS['s_login']['database'], $table);
    $columns_list = '';
    if ($export['sql']['cnames']) {
        $quote = $export['sql']['qnames'] ? '"' : '';
        $columns_list = '(' . $quote . implode($quote . ', ' . $quote, $export['query']['columns']) . $quote . ')';
    }
    $num = fbird_num_fields($export['query']['result']);
    // build one line for the csv file from every result object
    while ($row = @fbird_fetch_row($export['query']['result'], IBASE_TEXT)) {
        $values_list = '';
        for ($idx = 0; $idx < $num; $idx++) {
            if ($row[$idx] === NULL) {
                $value = $replace_null;
            } else {
                $value = prepare_export_value($row[$idx], $export['query']['col_types'][$idx]);
            }
            $values_list .= $export['query']['num_fields'][$idx] || $row[$idx] === NULL ? $value . ', ' : "'" . $value . "', ";
        }
        $values_list = '(' . substr($values_list, 0, -2) . ')';
        echo 'INSERT INTO ' . $target_table . ' ' . $columns_list . ' VALUES ' . $values_list . ';' . $line_ending;
    }
    echo $line_ending;
}
function print_rows_sp($wt)
{
    global $dbhandle, $ib_error;
    $types = get_column_types($wt['table'], $wt['columns']);
    $col_count = count($wt['columns']);
    $class = 'wttr2';
    $sql = 'SELECT * FROM ' . SP_LIMIT_NAME;
    $res = fbird_query($dbhandle, $sql) or $ib_error = fbird_errmsg();
    while ($row = fbird_fetch_row($res)) {
        unset($obj);
        foreach ($wt['columns'] as $idx => $colname) {
            $obj[$colname] = isset($row[$idx]) ? $row[$idx] : '';
        }
        settype($obj, 'object');
        $class = $class == 'wttr1' ? 'wttr2' : 'wttr1';
        echo '<tr class="wttr ' . $class . '">';
        for ($k = 0; $k < $col_count; $k++) {
            if (!isset($row[$k])) {
                print_value($wt, NULL, NULL);
            } else {
                print_value($wt, $row[$k], $types[$wt['columns'][$k]], $wt['columns'][$k], $obj);
            }
        }
        // get parameter for the edit and/or del link
        if ($wt['edit'] == TRUE || $wt['delete'] == TRUE) {
            build_editdel_links($obj, $wt['edit'], $wt['delete']);
            echo "</tr>\n";
        }
    }
    fbird_free_result($res);
}
Пример #6
0
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;
}