function get_domain_definitions($olddomains)
{
    global $dbhandle, $s_charsets;
    $sql = 'SELECT  F.RDB$FIELD_NAME AS DNAME,' . ' F.RDB$FIELD_TYPE AS FTYPE,' . ' F.RDB$FIELD_SUB_TYPE AS STYPE,' . ' F.RDB$FIELD_LENGTH AS FLEN,' . ' F.RDB$FIELD_PRECISION AS FPREC,' . ' F.RDB$FIELD_SCALE AS FSCALE,' . ' F.RDB$SEGMENT_LENGTH AS SEGLEN,' . ' F.RDB$CHARACTER_SET_ID AS CHARID,' . ' F.RDB$COLLATION_ID AS COLLID,' . ' F.RDB$NULL_FLAG AS NFLAG,' . ' F.RDB$DEFAULT_SOURCE AS DSOURCE,' . ' F.RDB$VALIDATION_SOURCE AS VSOURCE' . ' FROM  RDB$FIELDS F ' . ' WHERE  (RDB$SYSTEM_FLAG=0 OR RDB$SYSTEM_FLAG IS NULL)' . " AND  RDB\$FIELD_NAME NOT STARTING WITH 'RDB\$'" . ' ORDER  BY F.RDB$FIELD_NAME';
    $res = fbird_query($dbhandle, $sql) or ib_error(__FILE__, __LINE__, $sql);
    $domains = array();
    while ($obj = fbird_fetch_object($res)) {
        $dname = trim($obj->DNAME);
        $stype = isset($obj->STYPE) ? $obj->STYPE : 0;
        $domains[$dname]['type'] = get_datatype($obj->FTYPE, $stype);
        if ($stype != 0) {
            $domains[$dname]['stype'] = $stype;
        }
        if ($domains[$dname]['type'] == 'VARCHAR' || $domains[$dname]['type'] == 'CHARACTER') {
            $domains[$dname]['size'] = $obj->FLEN;
        }
        if (isset($obj->CHARID)) {
            $domains[$dname]['charset'] = $s_charsets[$obj->CHARID]['name'];
        }
        $domains[$dname]['collate'] = isset($obj->COLLID) && $obj->COLLID != 0 ? $s_charsets[$obj->CHARID]['collations'][$obj->COLLID] : NULL;
        if ($domains[$dname]['type'] == 'DECIMAL' || $domains[$dname]['type'] == 'NUMERIC') {
            $domains[$dname]['prec'] = $obj->FPREC;
            $domains[$dname]['scale'] = -$obj->FSCALE;
        }
        if ($domains[$dname]['type'] == 'BLOB') {
            $domains[$dname]['segsize'] = $obj->SEGLEN;
        }
        $domains[$dname]['notnull'] = isset($obj->NFLAG) && !empty($obj->NFLAG) ? TRUE : FALSE;
        $domains[$dname]['default'] = isset($obj->DSOURCE) && !empty($obj->DSOURCE) ? get_domain_default($dname) : '';
        $domains[$dname]['check'] = isset($obj->VSOURCE) && !empty($obj->VSOURCE) ? get_domain_check($dname) : '';
        $domains[$dname]['status'] = isset($olddomains[$dname]) ? $olddomains[$dname]['status'] : 'close';
    }
    fbird_free_result($res);
    return $domains;
}
function get_exceptions($order = 1, $dir = 'ASC')
{
    global $dbhandle;
    $sql = 'SELECT E.RDB$EXCEPTION_NAME AS ENAME,' . ' E.RDB$MESSAGE AS MSG' . ' FROM RDB$EXCEPTIONS E' . ' ORDER BY ' . $order . ' ' . $dir;
    $res = fbird_query($dbhandle, $sql) or ib_error(__FILE__, __LINE__, $sql);
    $exceptions = array();
    while ($obj = fbird_fetch_object($res)) {
        $exceptions[trim($obj->ENAME)] = trim($obj->MSG);
    }
    return $exceptions;
}
function get_foreignkeys($tablename, $privilege = NULL)
{
    $sql = 'SELECT I2.RDB$RELATION_NAME FKTABLE,' . ' IS1.RDB$FIELD_NAME FKFIELD,' . ' IS2.RDB$FIELD_NAME TFIELD' . ' FROM RDB$RELATION_CONSTRAINTS RC' . ' INNER JOIN RDB$INDICES I1 ON RC.RDB$INDEX_NAME=I1.RDB$INDEX_NAME' . ' INNER JOIN RDB$INDICES I2 ON I1.RDB$FOREIGN_KEY=I2.RDB$INDEX_NAME' . ' INNER JOIN RDB$INDEX_SEGMENTS IS1 ON I2.RDB$INDEX_NAME=IS1.RDB$INDEX_NAME' . ' INNER JOIN RDB$INDEX_SEGMENTS IS2 ON I1.RDB$INDEX_NAME=IS2.RDB$INDEX_NAME' . " WHERE RC.RDB\$RELATION_NAME='" . $tablename . "'" . " AND RC.RDB\$CONSTRAINT_TYPE='FOREIGN KEY'" . ' AND I1.RDB$SEGMENT_COUNT=1';
    $res = @fbird_query($GLOBALS['dbhandle'], $sql) or ib_error(__FILE__, __LINE__, $sql);
    $fk = array();
    while ($row = fbird_fetch_object($res)) {
        $fktable = trim($row->FKTABLE);
        if (empty($privilege) || in_array($privilege, $GLOBALS['s_tables'][$fktable]['privileges'])) {
            $fk[trim($row->TFIELD)] = array('table' => $fktable, 'column' => trim($row->FKFIELD));
        }
    }
    fbird_free_result($res);
    return $fk;
}
Esempio n. 4
0
function get_udfs($order = 1, $dir = 'ASC')
{
    global $dbhandle;
    $sql = 'SELECT F.RDB$FUNCTION_NAME AS FNAME,' . ' F.RDB$MODULE_NAME AS MODULE,' . ' F.RDB$ENTRYPOINT AS EPOINT,' . ' F.RDB$RETURN_ARGUMENT AS RPOS,' . ' A.RDB$ARGUMENT_POSITION AS APOS,' . ' A.RDB$FIELD_TYPE AS FTYPE,' . ' A.RDB$FIELD_SUB_TYPE AS STYPE,' . ' A.RDB$FIELD_SCALE AS SCALE,' . ' A.RDB$FIELD_LENGTH AS FLENGTH,' . ' A.RDB$FIELD_PRECISION AS PREC' . ' FROM RDB$FUNCTIONS F' . ' INNER JOIN RDB$FUNCTION_ARGUMENTS A' . ' ON F.RDB$FUNCTION_NAME=A.RDB$FUNCTION_NAME' . ' ORDER BY ' . $order . ' ' . $dir;
    $res = fbird_query($dbhandle, $sql) or ib_error($sql);
    $udfs = array();
    while ($obj = fbird_fetch_object($res)) {
        $fname = trim($obj->FNAME);
        $udfs[$fname]['module'] = trim($obj->MODULE);
        $udfs[$fname]['entrypoint'] = trim($obj->EPOINT);
        if ($obj->APOS == $obj->RPOS) {
            $udfs[$fname]['returns'] = get_datatype($obj->FTYPE, $obj->STYPE) . get_datatye_size_string($obj->FTYPE, $obj->FLENGTH, $obj->PREC, $obj->SCALE);
        } else {
            $udfs[$fname]['params'][$obj->APOS] = get_datatype($obj->FTYPE, $obj->STYPE) . get_datatye_size_string($obj->FTYPE, $obj->FLENGTH, $obj->PREC, $obj->SCALE);
        }
    }
    return $udfs;
}
function get_trigger_source($name)
{
    global $dbhandle;
    $tsource = '';
    $lsql = 'SELECT RDB$TRIGGER_SOURCE AS TSOURCE' . ' FROM RDB$TRIGGERS' . " WHERE RDB\$TRIGGER_NAME='" . $name . "'";
    $res = fbird_query($dbhandle, $lsql) or ib_error(__FILE__, __LINE__, $lsql);
    $obj = fbird_fetch_object($res);
    if (is_object($obj)) {
        $bid = fbird_blob_open($obj->TSOURCE);
        $arr = fbird_blob_info($obj->TSOURCE);
        // $arr[0] holds the blob length
        $tsource = trim(fbird_blob_get($bid, $arr[0]));
        fbird_blob_close($bid);
        // discard the 'AS ' from the source-string
        $tsource = substr($tsource, 3);
    }
    fbird_free_result($res);
    return $tsource;
}
    if (isset($_POST['acc_modind_cancel'])) {
        unset($s_mod_index);
    }
}
//
// generator stuff
//
if (have_panel_permissions($s_login['user'], 'acc_gen', TRUE)) {
    $quote = identifier_quote($s_login['dialect']);
    // init array generators[]
    $lsql = 'SELECT RDB$GENERATOR_NAME AS GNAME FROM RDB$GENERATORS ' . 'WHERE RDB$SYSTEM_FLAG IS NULL OR RDB$SYSTEM_FLAG = 0';
    $res = fbird_query($dbhandle, $lsql) or ib_error();
    while ($row = fbird_fetch_object($res)) {
        $lsql = 'SELECT gen_id(' . $quote . fb_escape_string($row->GNAME) . $quote . ', 0) AS VAL FROM RDB$DATABASE';
        $res1 = fbird_query($dbhandle, $lsql) or ib_error();
        $row1 = fbird_fetch_object($res1);
        $generators[] = array('name' => trim($row->GNAME), 'value' => (int) $row1->VAL);
        fbird_free_result($res1);
    }
    // one of the Drop buttons on the generator panel was pushed
    if ($name = drop_generator_pushed()) {
        $deps = get_dependencies(OT_GENERATOR, $name);
        if (count($deps) > 0) {
            $message = sprintf($MESSAGES['HAVE_DEPENDENCIES'], $acc_strings['Generator'], $name, dependencies_string($deps));
        } else {
            if ($s_cust['askdel'] == TRUE) {
                $s_confirmations['generator'] = array('msg' => sprintf($MESSAGES['CONFIRM_GEN_DELETE'], $name), 'obj' => $name);
            } else {
                drop_generator($name);
            }
        }
function get_table_fields($name)
{
    global $dbhandle;
    // get the field names and types
    $sql = 'SELECT RDB$FIELD_NAME AS FNAME' . ' FROM RDB$RELATION_FIELDS' . ' WHERE RDB$RELATION_NAME=\'' . $name . '\'' . ' ORDER BY RDB$FIELD_NAME';
    $res = fbird_query($dbhandle, $sql) or ib_error(__FILE__, __LINE__, $sql);
    $columns = array();
    while ($row = fbird_fetch_object($res)) {
        $columns[] = trim($row->FNAME);
    }
    fbird_free_result($res);
    return $columns;
}
function get_procedure_parameters($name)
{
    global $dbhandle, $s_charsets;
    $sql = 'SELECT P.RDB$PARAMETER_NAME PNAME,' . ' P.RDB$PARAMETER_TYPE PTYPE,' . ' F.RDB$FIELD_NAME AS DNAME,' . ' F.RDB$FIELD_TYPE AS FTYPE,' . ' F.RDB$FIELD_SUB_TYPE AS STYPE,' . ' F.RDB$FIELD_LENGTH AS FLEN,' . ' F.RDB$FIELD_PRECISION AS FPREC,' . ' F.RDB$FIELD_SCALE AS FSCALE,' . ' F.RDB$SEGMENT_LENGTH AS SEGLEN,' . ' F.RDB$CHARACTER_SET_ID AS CHARID,' . ' F.RDB$COLLATION_ID AS COLLID' . ' FROM RDB$PROCEDURE_PARAMETERS P' . ' INNER JOIN RDB$FIELDS F ON P.RDB$FIELD_SOURCE=F.RDB$FIELD_NAME' . " WHERE P.RDB\$PROCEDURE_NAME='" . $name . "'";
    $res = fbird_query($dbhandle, $sql) or ib_error(__FILE__, __LINE__, $sql);
    $in = $out = array();
    while ($obj = fbird_fetch_object($res)) {
        $ptype = $obj->PTYPE == 0 ? 'in' : 'out';
        $stype = isset($obj->STYPE) ? $obj->STYPE : NULL;
        $type = get_datatype($obj->FTYPE, $stype);
        if (in_array($type, array('DECIMAL', 'NUMERIC'))) {
            $prec = $obj->FPREC;
            $scale = -$obj->FSCALE;
            $stype = NULL;
        } else {
            $prec = $scale = NULL;
        }
        ${$ptype}[] = array('name' => trim($obj->PNAME), 'type' => $type, 'stype' => $stype, 'size' => in_array($type, array('VARCHAR', 'CHARACTER')) ? $obj->FLEN : NULL, 'charset' => isset($obj->CHARID) ? $s_charsets[$obj->CHARID]['name'] : NULL, 'collate' => isset($obj->COLLID) && $obj->COLLID != 0 ? $s_charsets[$obj->CHARID]['collations'][$obj->COLLID] : NULL, 'prec' => $prec, 'scale' => $scale, 'segsize' => $type == 'BLOB' ? $obj->SEGLEN : NULL);
    }
    return array($in, $out);
}
function systable_value_select($table, $field, $value = NULL)
{
    global $dbhandle, $db_strings;
    $sql = 'SELECT DISTINCT ' . $field . ' AS FNAME FROM ' . $table;
    $res = fbird_query($dbhandle, $sql) or ib_error(__FILE__, __LINE__, $sql);
    $values = array();
    while ($row = fbird_fetch_object($res)) {
        $values[] = trim($row->FNAME);
    }
    fbird_free_result($res);
    return '<b>' . $db_strings['FValue'] . "</b><br>\n" . get_selectlist('db_sysvalue', $values, $value, TRUE);
}
function print_rows_nosp($wt)
{
    global $dbhandle;
    $types = get_column_types($wt['table'], $wt['columns']);
    $class = 'wttr2';
    $quote = identifier_quote($GLOBALS['s_login']['dialect']);
    $sql = 'SELECT ';
    $sql .= $quote . implode($quote . ',' . $quote, $wt['columns']) . $quote . ' FROM ' . $quote . $wt['table'] . $quote;
    $sql .= $wt['condition'] != '' ? ' WHERE ' . $wt['condition'] : '';
    if (!empty($wt['order'])) {
        $sql .= ' ORDER BY ' . $wt['order'] . ' ' . $wt['direction'];
    }
    $sql .= ' ROWS ' . $wt['start'] . ' TO ' . ($wt['start'] + $wt['rows'] - 1);
    $res = @fbird_query($dbhandle, $sql) or ib_error(__FILE__, __LINE__, $sql);
    $col_count = count($wt['columns']);
    echo "  <tbody>\n";
    for ($i = 0; $i < $wt['rows']; $i++) {
        $obj = fbird_fetch_object($res);
        // stop, if there are no more rows
        if (!is_object($obj)) {
            break;
        }
        $class = $class == 'wttr1' ? 'wttr2' : 'wttr1';
        echo '    <tr class="wttr ' . $class . '">';
        $arr = get_object_vars($obj);
        for ($k = 0; $k < $col_count; $k++) {
            if (!isset($arr[$wt['columns'][$k]])) {
                print_value($wt, NULL, NULL);
            } else {
                print_value($wt, $arr[$wt['columns'][$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";
    }
    echo "  </tbody>\n";
    fbird_free_result($res);
}
Esempio n. 11
0
function get_view_source($name)
{
    global $dbhandle;
    $vsource = '';
    $sql = 'SELECT R.RDB$VIEW_SOURCE VSOURCE' . ' FROM RDB$RELATIONS R' . " WHERE R.RDB\$RELATION_NAME='" . $name . "'";
    $res = fbird_query($dbhandle, $sql) or ib_error(__FILE__, __LINE__, $sql);
    $obj = fbird_fetch_object($res);
    if (is_object($obj)) {
        $bid = fbird_blob_open($obj->VSOURCE);
        $arr = fbird_blob_info($obj->VSOURCE);
        // $arr[0] holds the blob length
        $vsource = trim(fbird_blob_get($bid, $arr[0]));
        fbird_blob_close($bid);
    }
    fbird_free_result($res);
    return $vsource;
}
function get_tables()
{
    global $dbhandle, $ib_error, $s_tables, $s_fields, $s_foreigns, $s_primaries, $s_uniques, $s_login;
    global $s_charsets, $s_tables_counts, $s_views_counts, $s_tables_def, $s_tables_comp;
    $previous = $s_tables;
    $s_tables = array();
    $s_fields = array();
    // get the tablenames, owner and view flag
    $sql = 'SELECT RDB$RELATION_NAME AS RNAME,' . ' RDB$VIEW_BLR AS VBLR,' . ' RDB$OWNER_NAME AS OWNER' . ' FROM RDB$RELATIONS' . ' WHERE RDB$SYSTEM_FLAG=0' . ' ORDER BY RDB$RELATION_NAME';
    $res = @fbird_query($dbhandle, $sql) or ib_error(__FILE__, __LINE__, $sql);
    if (!is_resource($res)) {
        return FALSE;
    }
    // initialize $s_tables[]
    while ($row = fbird_fetch_object($res)) {
        $tablename = trim($row->RNAME);
        $s_tables[$tablename]['status'] = isset($previous[$tablename]) ? $previous[$tablename]['status'] : 'close';
        $s_tables[$tablename]['is_view'] = isset($row->VBLR) && $row->VBLR !== NULL ? TRUE : FALSE;
        $s_tables[$tablename]['owner'] = trim($row->OWNER);
        $s_tables[$tablename]['privileges'] = array();
    }
    fbird_free_result($res);
    unset($previous);
    // get privileges on tables for the current user and for the role used at login
    $sql = 'SELECT R.RDB$RELATION_NAME AS RNAME,' . ' P1.RDB$PRIVILEGE AS PRIV' . ' FROM RDB$RELATIONS R' . ' INNER JOIN RDB$USER_PRIVILEGES P1' . ' ON R.RDB$RELATION_NAME=P1.RDB$RELATION_NAME' . ' WHERE R.RDB$SYSTEM_FLAG=0' . " AND (P1.RDB\$USER='******'user'] . "' OR P1.RDB\$USER='******')";
    if (!empty($s_login['role'])) {
        $sql .= ' UNION' . ' SELECT R.RDB$RELATION_NAME AS RNAME,' . ' P2.RDB$PRIVILEGE AS PRIV' . ' FROM RDB$USER_PRIVILEGES P1' . ' INNER JOIN RDB$USER_PRIVILEGES P2 ON P1.RDB$RELATION_NAME=P2.RDB$USER' . ' INNER JOIN RDB$RELATIONS R ON R.RDB$RELATION_NAME=P2.RDB$RELATION_NAME' . " WHERE P1.RDB\$PRIVILEGE='M'" . ' AND R.RDB$SYSTEM_FLAG=0' . " AND P1.RDB\$RELATION_NAME='" . $s_login['role'] . "'" . " AND (P1.RDB\$USER='******'user'] . "' OR P1.RDB\$USER='******')";
    }
    $res = @fbird_query($dbhandle, $sql) or ib_error(__FILE__, __LINE__, $sql);
    while ($row = fbird_fetch_object($res)) {
        $s_tables[trim($row->RNAME)]['privileges'][] = trim($row->PRIV);
    }
    fbird_free_result($res);
    // find the check, not null, unique, pk and fk and  constraints
    $sql = 'SELECT RC.RDB$RELATION_NAME TNAME,' . ' RC.RDB$CONSTRAINT_TYPE RTYPE,' . ' RC.RDB$CONSTRAINT_NAME CNAME,' . ' RC.RDB$INDEX_NAME INAME,' . ' CC.RDB$TRIGGER_NAME TRIGNAME,' . ' SE.RDB$FIELD_NAME SENAME,' . ' SE.RDB$FIELD_POSITION POS,' . ' DP.RDB$FIELD_NAME DPNAME' . ' FROM RDB$RELATION_CONSTRAINTS RC' . ' LEFT JOIN RDB$CHECK_CONSTRAINTS CC' . ' ON RC.RDB$CONSTRAINT_NAME=CC.RDB$CONSTRAINT_NAME' . " AND RC.RDB\$CONSTRAINT_TYPE='CHECK'" . ' LEFT JOIN RDB$INDEX_SEGMENTS SE' . ' ON RC.RDB$INDEX_NAME=SE.RDB$INDEX_NAME' . ' LEFT JOIN RDB$DEPENDENCIES DP' . ' ON CC.RDB$TRIGGER_NAME=DP.RDB$DEPENDENT_NAME' . ' ORDER BY RC.RDB$RELATION_NAME';
    $res = @fbird_query($dbhandle, $sql) or ib_error(__FILE__, __LINE__, $sql);
    // reset the index infos
    $s_foreigns = array();
    $s_primaries = array();
    $s_uniques = array();
    $constraints = array();
    while ($row = fbird_fetch_object($res)) {
        $cname = trim($row->CNAME);
        switch (trim($row->RTYPE)) {
            case 'CHECK':
                $constraints[trim($row->TNAME)][trim($row->DPNAME)]['check'] = $cname;
                break;
            case 'UNIQUE':
                $constraints[trim($row->TNAME)][trim($row->SENAME)]['unique'] = $cname;
                $s_uniques[$cname]['index'] = trim($row->INAME);
                $s_uniques[$cname]['cols'] = isset($s_uniques[$cname]['cols']) ? $s_uniques[$cname]['cols']++ : 1;
                break;
            case 'FOREIGN KEY':
                $constraints[trim($row->TNAME)][trim($row->SENAME)]['foreign'] = $cname;
                $s_foreigns[$cname]['index'] = trim($row->INAME);
                $s_foreigns[$cname]['cols'] = isset($s_foreigns[$cname]['cols']) ? $s_foreigns[$cname]['cols']++ : 1;
                break;
            case 'PRIMARY KEY':
                $constraints[trim($row->TNAME)][trim($row->SENAME)]['primary'] = $cname;
                $s_primaries[$cname]['index'] = trim($row->INAME);
                $s_primaries[$cname]['cols'] = isset($s_primaries[$cname]['cols']) ? $s_primaries[$cname]['cols']++ : 1;
                break;
        }
    }
    fbird_free_result($res);
    //     debug_var($sql);
    //     debug_var($constraints);
    //     debug_var($s_foreigns);
    //     debug_var($s_primaries);
    // find the field properties for all non-system tables
    $sql = 'SELECT DISTINCT R.RDB$FIELD_NAME AS FNAME,' . ' R.RDB$NULL_FLAG AS NFLAG,' . ' R.RDB$DEFAULT_SOURCE AS DSOURCE,' . ' R.RDB$FIELD_POSITION,' . ' R.RDB$RELATION_NAME AS TNAME,' . ' R.RDB$COLLATION_ID AS COLLID,' . ' F.RDB$FIELD_NAME AS DNAME,' . ' F.RDB$FIELD_TYPE AS FTYPE,' . ' F.RDB$FIELD_SUB_TYPE AS STYPE,' . ' F.RDB$FIELD_LENGTH AS FLEN,' . ' F.RDB$COMPUTED_SOURCE AS CSOURCE,' . ' F.RDB$FIELD_PRECISION AS FPREC,' . ' F.RDB$FIELD_SCALE AS FSCALE,' . ' F.RDB$SEGMENT_LENGTH AS SEGLEN,' . ' F.RDB$CHARACTER_SET_ID AS CHARID,' . ' D.RDB$LOWER_BOUND AS LBOUND,' . ' D.RDB$UPPER_BOUND AS UBOUND' . ' FROM RDB$RELATION_FIELDS R ' . ' JOIN RDB$FIELDS F ON R.RDB$FIELD_SOURCE=F.RDB$FIELD_NAME' . ' LEFT JOIN RDB$FIELD_DIMENSIONS D ON R.RDB$FIELD_SOURCE=D.RDB$FIELD_NAME' . ' WHERE F.RDB$SYSTEM_FLAG=0' . ' ORDER BY R.RDB$FIELD_POSITION';
    $res = @fbird_query($dbhandle, $sql) or ib_error(__FILE__, __LINE__, $sql);
    //initialize $s_fields[]
    $idx = 0;
    while ($row = fbird_fetch_object($res)) {
        $tname = trim($row->TNAME);
        $field = $s_fields[$tname][$idx]['name'] = trim($row->FNAME);
        if (strpos($row->DNAME, 'RDB$') !== 0) {
            $s_fields[$tname][$idx]['domain'] = 'Yes';
            $s_fields[$tname][$idx]['type'] = trim($row->DNAME);
        } else {
            $s_fields[$tname][$idx]['stype'] = isset($row->STYPE) ? $row->STYPE : NULL;
            $s_fields[$tname][$idx]['type'] = get_datatype($row->FTYPE, $s_fields[$tname][$idx]['stype']);
        }
        if ($s_fields[$tname][$idx]['type'] == 'VARCHAR' || $s_fields[$tname][$idx]['type'] == 'CHARACTER') {
            $s_fields[$tname][$idx]['size'] = $row->FLEN;
        }
        // field is defined as NOT NULL
        if (!empty($row->NFLAG)) {
            $s_fields[$tname][$idx]['notnull'] = 'Yes';
        }
        // this field is computed
        if (isset($row->CSOURCE)) {
            $s_fields[$tname][$idx]['comp'] = 'Yes';
            $s_fields[$tname][$idx]['csource'] = FALSE;
        }
        // this field has a default value
        if (isset($row->DSOURCE)) {
            $s_fields[$tname][$idx]['default'] = 'Yes';
            $s_fields[$tname][$idx]['dsource'] = FALSE;
        }
        if ($s_fields[$tname][$idx]['type'] == 'DECIMAL' or $s_fields[$tname][$idx]['type'] == 'NUMERIC') {
            $s_fields[$tname][$idx]['prec'] = $row->FPREC;
            $s_fields[$tname][$idx]['scale'] = -$row->FSCALE;
        }
        if ($s_fields[$tname][$idx]['type'] == 'BLOB') {
            $s_fields[$tname][$idx]['segsize'] = $row->SEGLEN;
        }
        $s_fields[$tname][$idx]['charset'] = isset($row->CHARID) ? $s_charsets[$row->CHARID]['name'] : NULL;
        $s_fields[$tname][$idx]['collate'] = isset($row->COLLID) && $row->COLLID != 0 && isset($s_charsets[$row->CHARID]['collations'][$row->COLLID]) ? $s_charsets[$row->CHARID]['collations'][$row->COLLID] : NULL;
        // optional array dimensions
        if (isset($row->LBOUND)) {
            $s_fields[$tname][$idx]['lower_bound'] = $row->LBOUND;
            $s_fields[$tname][$idx]['upper_bound'] = $row->UBOUND;
        }
        // column constraints
        foreach (array('check', 'unique', 'foreign', 'primary') as $ctype) {
            if (isset($constraints[$tname][$field][$ctype])) {
                $s_fields[$tname][$idx][$ctype] = $constraints[$tname][$field][$ctype];
            }
        }
        $idx++;
    }
    //     debug_var($s_fields);
    $quote = identifier_quote($s_login['dialect']);
    foreach ($s_tables as $name => $properties) {
        if ($s_tables_def == TRUE) {
            $s_fields = get_table_defaults_sources($name, $s_fields);
        }
        if ($s_tables_comp == TRUE) {
            $s_fields = get_table_computed_sources($name, $s_fields);
        }
        if (!in_array('S', $properties['privileges'])) {
            continue;
        }
        if ($properties['is_view'] == FALSE && $s_tables_counts == TRUE || $properties['is_view'] == TRUE && $s_views_counts == TRUE) {
            $sql = 'SELECT COUNT(*) AS CNT FROM ' . $quote . $name . $quote;
            $res = fbird_query($dbhandle, $sql) or $ib_error .= fbird_errmsg() . "<br>\n";
            if (is_resource($res)) {
                $row = fbird_fetch_object($res);
                $s_tables[$name]['count'] = $row->CNT;
                fbird_free_result($res);
            }
        }
    }
    return TRUE;
}
Esempio n. 13
0
     }
 } elseif ($s_connected == TRUE && empty($error)) {
     $s_sql['more'] = FALSE;
     $results = array();
     foreach ($lines as $lnr => $cmd) {
         $cnt = 0;
         $trans = fbird_trans(TRANS_WRITE, $dbhandle);
         $res = @fbird_query($trans, $cmd) or $ib_error = fbird_errmsg();
         // if sql_output-panel is open
         $idx = get_panel_index($s_sql_panels, 'sql_output');
         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();
     }
 }
Esempio n. 14
0
function get_roles()
{
    global $dbhandle;
    $sql = 'SELECT R.RDB$ROLE_NAME AS NAME,' . ' R.RDB$OWNER_NAME AS OWNER,' . ' P.RDB$USER AS MEMBER' . ' FROM RDB$ROLES R' . ' LEFT JOIN RDB$USER_PRIVILEGES P' . ' ON R.RDB$ROLE_NAME=P.RDB$RELATION_NAME' . " AND P.RDB\$PRIVILEGE='M'" . 'ORDER BY R.RDB$ROLE_NAME';
    $res = fbird_query($dbhandle, $sql) or ib_error();
    $roles = array();
    $lastone = '';
    while ($obj = fbird_fetch_object($res)) {
        $rname = trim($obj->NAME);
        $member = isset($obj->MEMBER) ? trim($obj->MEMBER) : '';
        if ($rname == $lastone) {
            $roles[$rname]['members'][] = $member;
            continue;
        }
        $roles[$rname]['owner'] = trim($obj->OWNER);
        $roles[$rname]['members'] = !empty($member) ? array($member) : array();
        $lastone = $rname;
    }
    return $roles;
}
function fk_values($table, $column, $value)
{
    $sql = sprintf("SELECT * FROM %s WHERE %s='%s'", $table, $column, $value);
    $res = fbird_query($GLOBALS['dbhandle'], $sql) or ib_error(__FILE__, __LINE__, $sql);
    if ($row = fbird_fetch_object($res)) {
        $close = "<a href='javascript:hide(\"fk\");'>[C]</a>";
        $html = "<table class=\"table table-bordered tsep\">\n<tr align=\"left\">\n<th colspan=\"2\"><nobr>" . $close . '&nbsp;&nbsp;' . $sql . "</nobr></th></tr>\n";
        foreach ($GLOBALS['s_fields'][$table] as $field) {
            $value = $field['type'] == 'BLOB' ? '<i>BLOB</i>' : trim($row->{$field}['name']);
            $html .= sprintf("<tr>\n<td class=\"wttr wttr1\">%s:</td><td class=\"wttr2\"><nobr>%s</nobr></td>\n</tr>\n", $field['name'], $value);
        }
        $html .= "</table>\n";
    } else {
        $html = "Error!\n";
    }
    fbird_free_result($res);
    header('Content-Type: text/html;charset=' . $GLOBALS['charset']);
    echo $html;
}
Esempio n. 16
0
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;
}