Example #1
0
/**
 * This is a callback function to display the result of each separate query
 * @param ADORecordSet $rs The recordset returned by the script execetor
 */
function sqlCallback($query, $rs, $lineno)
{
    global $data, $misc, $lang, $_connection;
    // Check if $rs is false, if so then there was a fatal error
    if ($rs === false) {
        echo htmlspecialchars($_FILES['script']['name']), ':', $lineno, ': ', nl2br(htmlspecialchars($_connection->getLastError())), "<br/>\n";
    } else {
        // Print query results
        switch (pg_result_status($rs)) {
            case PGSQL_TUPLES_OK:
                // If rows returned, then display the results
                $num_fields = pg_numfields($rs);
                echo "<p><table>\n<tr>";
                for ($k = 0; $k < $num_fields; $k++) {
                    echo "<th class=\"data\">", $misc->printVal(pg_fieldname($rs, $k)), "</th>";
                }
                $i = 0;
                $row = pg_fetch_row($rs);
                while ($row !== false) {
                    $id = $i % 2 == 0 ? '1' : '2';
                    echo "<tr class=\"data{$id}\">\n";
                    foreach ($row as $k => $v) {
                        echo "<td style=\"white-space:nowrap;\">", $misc->printVal($v, pg_fieldtype($rs, $k), array('null' => true)), "</td>";
                    }
                    echo "</tr>\n";
                    $row = pg_fetch_row($rs);
                    $i++;
                }
                echo "</table><br/>\n";
                echo $i, " {$lang['strrows']}</p>\n";
                break;
            case PGSQL_COMMAND_OK:
                // If we have the command completion tag
                if (version_compare(phpversion(), '4.3', '>=')) {
                    echo htmlspecialchars(pg_result_status($rs, PGSQL_STATUS_STRING)), "<br/>\n";
                } elseif ($data->conn->Affected_Rows() > 0) {
                    echo $data->conn->Affected_Rows(), " {$lang['strrowsaff']}<br/>\n";
                }
                // Otherwise output nothing...
                break;
            case PGSQL_EMPTY_QUERY:
                break;
            default:
                break;
        }
    }
}
Example #2
0
function vty_field_name($list,$i){
        switch($this->vtAdi){
        case 'mysql': return mysql_field_name($list,$i); break;
        case 'odbc': return odbc_field_name($list,$i); break;
        case 'mssql': return mssql_field_name($list,$i); break;
        case 'postgresql': return pg_fieldname($list,$i); break;
        }
}
Example #3
0
 /**
  * Returns information about a table or a result set.
  *
  * NOTE: only supports 'table' and 'flags' if <var>$result</var>
  * is a table name.
  *
  * @param object|string  $result  DB_result object from a query or a
  *                                string containing the name of a table
  * @param int            $mode    a valid tableInfo mode
  * @return array  an associative array with the information requested
  *                or an error object if something is wrong
  * @access public
  * @internal
  * @see DB_common::tableInfo()
  */
 function tableInfo($result, $mode = null)
 {
     if (isset($result->result)) {
         /*
          * Probably received a result object.
          * Extract the result resource identifier.
          */
         $id = $result->result;
         $got_string = false;
     } elseif (is_string($result)) {
         /*
          * Probably received a table name.
          * Create a result resource identifier.
          */
         $id = @pg_exec($this->connection, "SELECT * FROM {$result} LIMIT 0");
         $got_string = true;
     } else {
         /*
          * Probably received a result resource identifier.
          * Copy it.
          * Deprecated.  Here for compatibility only.
          */
         $id = $result;
         $got_string = false;
     }
     if (!is_resource($id)) {
         return $this->pgsqlRaiseError(DB_ERROR_NEED_MORE_DATA);
     }
     if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
         $case_func = 'strtolower';
     } else {
         $case_func = 'strval';
     }
     $count = @pg_numfields($id);
     // made this IF due to performance (one if is faster than $count if's)
     if (!$mode) {
         for ($i = 0; $i < $count; $i++) {
             $res[$i]['table'] = $got_string ? $case_func($result) : '';
             $res[$i]['name'] = $case_func(@pg_fieldname($id, $i));
             $res[$i]['type'] = @pg_fieldtype($id, $i);
             $res[$i]['len'] = @pg_fieldsize($id, $i);
             $res[$i]['flags'] = $got_string ? $this->_pgFieldflags($id, $i, $result) : '';
         }
     } else {
         // full
         $res['num_fields'] = $count;
         for ($i = 0; $i < $count; $i++) {
             $res[$i]['table'] = $got_string ? $case_func($result) : '';
             $res[$i]['name'] = $case_func(@pg_fieldname($id, $i));
             $res[$i]['type'] = @pg_fieldtype($id, $i);
             $res[$i]['len'] = @pg_fieldsize($id, $i);
             $res[$i]['flags'] = $got_string ? $this->_pgFieldFlags($id, $i, $result) : '';
             if ($mode & DB_TABLEINFO_ORDER) {
                 $res['order'][$res[$i]['name']] = $i;
             }
             if ($mode & DB_TABLEINFO_ORDERTABLE) {
                 $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
             }
         }
     }
     // free the result only if we were called on a table
     if ($got_string) {
         @pg_freeresult($id);
     }
     return $res;
 }
Example #4
0
 /**
  * Get a column's flags
  *
  * Supports "not_null", "default_value", "primary_key", "unique_key"
  * and "multiple_key".  The default value is passed through
  * rawurlencode() in case there are spaces in it.
  *
  * @param int $resource   the PostgreSQL result identifier
  * @param int $num_field  the field number
  *
  * @return string  the flags
  *
  * @access private
  */
 function _pgFieldFlags($resource, $num_field, $table_name)
 {
     $field_name = @pg_fieldname($resource, $num_field);
     // Check if there's a schema in $table_name and update things
     // accordingly.
     $from = 'pg_attribute f, pg_class tab, pg_type typ';
     if (strpos($table_name, '.') !== false) {
         $from .= ', pg_namespace nsp';
         list($schema, $table) = explode('.', $table_name);
         $tableWhere = "tab.relname = '{$table}' AND tab.relnamespace = nsp.oid AND nsp.nspname = '{$schema}'";
     } else {
         $tableWhere = "tab.relname = '{$table_name}'";
     }
     $result = @pg_exec($this->connection, "SELECT f.attnotnull, f.atthasdef\n                                FROM {$from}\n                                WHERE tab.relname = typ.typname\n                                AND typ.typrelid = f.attrelid\n                                AND f.attname = '{$field_name}'\n                                AND {$tableWhere}");
     if (@pg_numrows($result) > 0) {
         $row = @pg_fetch_row($result, 0);
         $flags = $row[0] == 't' ? 'not_null ' : '';
         if ($row[1] == 't') {
             $result = @pg_exec($this->connection, "SELECT a.adsrc\n                                    FROM {$from}, pg_attrdef a\n                                    WHERE tab.relname = typ.typname AND typ.typrelid = f.attrelid\n                                    AND f.attrelid = a.adrelid AND f.attname = '{$field_name}'\n                                    AND {$tableWhere} AND f.attnum = a.adnum");
             $row = @pg_fetch_row($result, 0);
             $num = preg_replace("/'(.*)'::\\w+/", "\\1", $row[0]);
             $flags .= 'default_' . rawurlencode($num) . ' ';
         }
     } else {
         $flags = '';
     }
     $result = @pg_exec($this->connection, "SELECT i.indisunique, i.indisprimary, i.indkey\n                                FROM {$from}, pg_index i\n                                WHERE tab.relname = typ.typname\n                                AND typ.typrelid = f.attrelid\n                                AND f.attrelid = i.indrelid\n                                AND f.attname = '{$field_name}'\n                                AND {$tableWhere}");
     $count = @pg_numrows($result);
     for ($i = 0; $i < $count; $i++) {
         $row = @pg_fetch_row($result, $i);
         $keys = explode(' ', $row[2]);
         if (in_array($num_field + 1, $keys)) {
             $flags .= $row[0] == 't' && $row[1] == 'f' ? 'unique_key ' : '';
             $flags .= $row[1] == 't' ? 'primary_key ' : '';
             if (count($keys) > 1) {
                 $flags .= 'multiple_key ';
             }
         }
     }
     return trim($flags);
 }
Example #5
0
 /**
  * Get a column's flags
  *
  * Supports "not_null", "default_value", "primary_key", "unique_key"
  * and "multiple_key".  The default value is passed through
  * rawurlencode() in case there are spaces in it.
  *
  * @param int $resource   the PostgreSQL result identifier
  * @param int $num_field  the field number
  *
  * @return string  the flags
  *
  * @access private
  */
 function _pgFieldFlags($resource, $num_field, $table_name)
 {
     $field_name = @pg_fieldname($resource, $num_field);
     $result = @pg_exec($this->connection, "SELECT f.attnotnull, f.atthasdef\n                                FROM pg_attribute f, pg_class tab, pg_type typ\n                                WHERE tab.relname = typ.typname\n                                AND typ.typrelid = f.attrelid\n                                AND f.attname = '{$field_name}'\n                                AND tab.relname = '{$table_name}'");
     if (@pg_numrows($result) > 0) {
         $row = @pg_fetch_row($result, 0);
         $flags = $row[0] == 't' ? 'not_null ' : '';
         if ($row[1] == 't') {
             $result = @pg_exec($this->connection, "SELECT a.adsrc\n                                    FROM pg_attribute f, pg_class tab, pg_type typ, pg_attrdef a\n                                    WHERE tab.relname = typ.typname AND typ.typrelid = f.attrelid\n                                    AND f.attrelid = a.adrelid AND f.attname = '{$field_name}'\n                                    AND tab.relname = '{$table_name}' AND f.attnum = a.adnum");
             $row = @pg_fetch_row($result, 0);
             $num = preg_replace("/'(.*)'::\\w+/", "\\1", $row[0]);
             $flags .= 'default_' . rawurlencode($num) . ' ';
         }
     } else {
         $flags = '';
     }
     $result = @pg_exec($this->connection, "SELECT i.indisunique, i.indisprimary, i.indkey\n                                FROM pg_attribute f, pg_class tab, pg_type typ, pg_index i\n                                WHERE tab.relname = typ.typname\n                                AND typ.typrelid = f.attrelid\n                                AND f.attrelid = i.indrelid\n                                AND f.attname = '{$field_name}'\n                                AND tab.relname = '{$table_name}'");
     $count = @pg_numrows($result);
     for ($i = 0; $i < $count; $i++) {
         $row = @pg_fetch_row($result, $i);
         $keys = explode(' ', $row[2]);
         if (in_array($num_field + 1, $keys)) {
             $flags .= $row[0] == 't' && $row[1] == 'f' ? 'unique_key ' : '';
             $flags .= $row[1] == 't' ? 'primary_key ' : '';
             if (count($keys) > 1) {
                 $flags .= 'multiple_key ';
             }
         }
     }
     return trim($flags);
 }
Example #6
0
 function GetColumnNames($result, &$column_names)
 {
     if (!isset($this->highest_fetched_row[$result])) {
         return $this->SetError("Get Column Names", "it was specified an inexisting result set");
     }
     if (!isset($this->columns[$result])) {
         $this->columns[$result] = array();
         $columns = pg_numfields($result);
         for ($column = 0; $column < $columns; $column++) {
             $this->columns[$result][strtolower(pg_fieldname($result, $column))] = $column;
         }
     }
     $column_names = $this->columns[$result];
     return 1;
 }
Example #7
0
function sec_showresult($result)
{
    $n = pg_numfields($result);
    echo '<table border=1 width="100%">';
    echo '<tr>';
    for ($j = 0; $j < $n; $j++) {
        $a = pg_fieldname($result, $j);
        echo "<td>{$a}</td>";
    }
    echo '</tr>';
    $rows = pg_numrows($result);
    for ($i = 0; $i < $rows; $i++) {
        echo '<tr>';
        $row = pg_fetch_row($result, $i);
        for ($j = 0; $j < $n; $j++) {
            echo "<td>{$row[$j]}</td>";
        }
        echo '</tr>';
    }
    echo '</table>';
    if ($rows == 0) {
        echo '<p><b>No matches found</b>';
    } else {
        echo "<p>{$rows} items found";
    }
}
/**
 *
 *  Returns the number of rows changed in the last query
 *
 *  @param qhandle - query result set handle
 *  @param fnumber - column number
 *
 */
function db_fieldname($lhandle, $fnumber)
{
    return @pg_fieldname($lhandle, $fnumber);
}
Example #9
0
 function GetColumnName($col)
 {
     return pg_fieldname($this->result, $col - 1);
 }
Example #10
0
 function FieldName($result, $offset)
 {
     switch ($this->dbType) {
         case "mssql":
             $r = mssql_field_name($result, $offset);
             break;
         case "mysql":
             $r = mysql_field_name($result, $offset);
             break;
         case "pg":
             $r = pg_fieldname($result, $offset);
             break;
         default:
             $r = False;
             break;
     }
     return $r;
 }
Example #11
0
        echo $strField;
        ?>
</th>
		<th><?php 
        echo $strType;
        ?>
</th>
		<th><?php 
        echo $strValue;
        ?>
</th>
		</tr>
		<?php 
        $result = pg_exec($link, pre_query($sql_get_fields));
        for ($i = 0; $i < pg_numfields($result); $i++) {
            $field = pg_fieldname($result, $i);
            $type = pg_fieldtype($result, $i);
            $len = pg_fieldsize($result, $i);
            if ($len < 1) {
                $len_disp = "var";
                $len = 50;
            } else {
                $len_disp = $len;
            }
            $bgcolor = $cfgBgcolorOne;
            $i % 2 ? 0 : ($bgcolor = $cfgBgcolorTwo);
            echo "<tr bgcolor=" . $bgcolor . ">";
            echo "<td>{$field}</td>";
            echo "<td>{$type} ({$len_disp})</td>";
            if ($type == "bool") {
                echo "<td><select name=fields[]><option value=\"t\">True<option value=\"f\">False</select></td>";
Example #12
0
 /**
  * Flags of a Field
  *
  * @param int $resource PostgreSQL result identifier
  * @param int $num_field the field number
  * @return string The flags of the field ('not_null', 'default_xx', 'primary_key',
  *                 'unique' and 'multiple_key' are supported)
  * @access private
  **/
 function _pgFieldFlags($resource, $num_field, $table_name)
 {
     $field_name = @pg_fieldname($resource, $num_field);
     $result = pg_exec($this->connection, "SELECT f.attnotnull, f.atthasdef\r\n            FROM pg_attribute f, pg_class tab, pg_type typ\r\n            WHERE tab.relname = typ.typname\r\n            AND typ.typrelid = f.attrelid\r\n            AND f.attname = '{$field_name}'\r\n            AND tab.relname = '{$table_name}'");
     if (@pg_numrows($result) > 0) {
         $row = @pg_fetch_row($result, 0);
         $flags = $row[0] == 't' ? 'not_null ' : '';
         if ($row[1] == 't') {
             $result = @pg_exec($this->connection, "SELECT a.adsrc\r\n                    FROM pg_attribute f, pg_class tab, pg_type typ, pg_attrdef a\r\n                    WHERE tab.relname = typ.typname AND typ.typrelid = f.attrelid\r\n                    AND f.attrelid = a.adrelid AND f.attname = '{$field_name}'\r\n                    AND tab.relname = '{$table_name}'");
             $row = @pg_fetch_row($result, 0);
             $num = str_replace('\'', '', $row[0]);
             $flags .= "default_{$num} ";
         }
     }
     $result = @pg_exec($this->connection, "SELECT i.indisunique, i.indisprimary, i.indkey\r\n            FROM pg_attribute f, pg_class tab, pg_type typ, pg_index i\r\n            WHERE tab.relname = typ.typname\r\n            AND typ.typrelid = f.attrelid\r\n            AND f.attrelid = i.indrelid\r\n            AND f.attname = '{$field_name}'\r\n            AND tab.relname = '{$table_name}'");
     $count = @pg_numrows($result);
     for ($i = 0; $i < $count; $i++) {
         $row = @pg_fetch_row($result, $i);
         $keys = explode(' ', $row[2]);
         if (in_array($num_field + 1, $keys)) {
             $flags .= $row[0] == 't' ? 'unique ' : '';
             $flags .= $row[1] == 't' ? 'primary ' : '';
             if (count($keys) > 1) {
                 $flags .= 'multiple_key ';
             }
         }
     }
     return trim($flags);
 }
 function GetFieldName($fieldIndex)
 {
     if ($this->res) {
         return pg_fieldname($this->res, $fieldIndex);
     }
     return '';
 }
 }
 // get the fields
 status("querying for data... ");
 $flds_rslt = pg_exec("SELECT * FROM \"{$schema}\".{$tbl_name}");
 status("done\n");
 $create_fields = array();
 // reset it
 $insert_fields = array();
 // reset it
 $sequences = array();
 status("creating create query...\n");
 for ($fld_num = 0; $fld_num < pg_numfields($flds_rslt); $fld_num++) {
     $nextval = false;
     // last sequence value
     // read the fieldname
     $f_name = pg_fieldname($flds_rslt, $fld_num);
     $f_info = $fields_info[$tbl_name][$f_name];
     status("done\n");
     // if field has a default value starting with nextval, get the sequence name
     $seq_name = array();
     status("checking for sequence... ");
     // true_ids is a column for which we should not recreate a sequence, they are
     // manually created (usually used for tables sharing 1 sequence)
     if ($f_name != "true_ids" && (preg_match("/^nextval\\('(.*)\\.(.*)'::text\\)/", $f_info["default"], $seq_name) || preg_match("/^nextval\\('(.*)\\.(.*)'::regclass\\)/", $f_info["default"], $seq_name))) {
         status(" (seq) ");
         $seq_schema = $seq_name[1];
         $seq_name = $seq_name[2];
         $f_type = "serial NOT NULL PRIMARY KEY";
         // read the next val it had
         $nval_rslt = pg_exec("SELECT last_value FROM {$seq_schema}.{$seq_name}");
         if (pg_num_rows($nval_rslt) > 0) {
 function parse_pgsql($file_id, $result_name)
 {
     global ${$result_name};
     $loop_code = '';
     $start_pos = strpos(strtolower($this->files[$file_id]), '<loop name="' . $result_name . '">') + strlen('<loop name="' . $result_name . '">');
     $end_pos = strpos(strtolower($this->files[$file_id]), '</loop name="' . $result_name . '">');
     $loop_code = substr($this->files[$file_id], $start_pos, $end_pos - $start_pos);
     $start_tag = substr($this->files[$file_id], strpos(strtolower($this->files[$file_id]), '<loop name="' . $result_name . '">'), strlen('<loop name="' . $result_name . '">'));
     $end_tag = substr($this->files[$file_id], strpos(strtolower($this->files[$file_id]), '</loop name="' . $result_name . '">'), strlen('</loop name="' . $result_name . '">'));
     if ($loop_code != '') {
         $new_code = '';
         $field_names = array();
         for ($i = 0; $i < pg_numfields(${$result_name}); $i++) {
             $field_names[] = pg_fieldname(${$result_name}, $i);
         }
         for ($i = 0; $i < pg_getNumberRows(${$result_name}) and $row_data = pg_fetch_array(${$result_name}, $i); $i++) {
             $temp_code = $loop_code;
             for ($j = 0; $j < count($field_names); $j++) {
                 $temp_code = str_replace($this->start . $field_names[$j] . $this->end, $row_data[$field_names[$j]], $temp_code);
             }
             $new_code .= $temp_code;
         }
         $this->files[$file_id] = str_replace($start_tag . $loop_code . $end_tag, $new_code, $this->files[$file_id]);
     }
 }
Example #16
0
 function get_table_content($link, $table, $handler)
 {
     global $cfgQuotes;
     $result = @pg_exec($link, "SELECT * FROM {$cfgQuotes}{$table}{$cfgQuotes}") or pg_die(pg_errormessage(), "", __FILE__, __LINE__);
     $iNumFields = pg_numfields($result);
     // Gather info about each column in the table
     for ($iField = 0; $iField < $iNumFields; $iField++) {
         $aryType[] = pg_fieldtype($result, $iField);
         $aryName[] = pg_fieldname($result, $iField);
     }
     $iRec = 0;
     while ($row = @pg_fetch_array($result, $iRec++)) {
         unset($schema_vals);
         unset($schema_fields);
         unset($schema_insert);
         for ($iFieldVal = 0; $iFieldVal < $iNumFields; $iFieldVal++) {
             $strVal = $row[$aryName[$iFieldVal]];
             if (eregi("char|text", $aryType[$iFieldVal])) {
                 $strQuote = "'";
                 $strEmpty = "";
                 $strVal = addslashes($strVal);
             } elseif (eregi("date|time|inet|bool", $aryType[$iFieldVal])) {
                 if (empty($strVal)) {
                     $strQuote = "";
                 } else {
                     $strQuote = "'";
                 }
                 $strEmpty = "NULL";
             } else {
                 $strQuote = "";
                 $strEmpty = "NULL";
             }
             if (empty($strVal) && $strVal != "0") {
                 $strVal = $strEmpty;
             }
             $schema_vals .= " {$strQuote}{$strVal}{$strQuote},";
             $schema_fields .= " {$cfgQuotes}{$aryName[$iFieldVal]}{$cfgQuotes},";
         }
         $schema_vals = ereg_replace(",\$", "", $schema_vals);
         $schema_vals = ereg_replace("^ ", "", $schema_vals);
         $schema_fields = ereg_replace(",\$", "", $schema_fields);
         $schema_fields = ereg_replace("^ ", "", $schema_fields);
         $schema_insert = "INSERT INTO {$cfgQuotes}{$table}{$cfgQuotes} ({$schema_fields}) VALUES({$schema_vals})";
         $handler(trim($schema_insert));
     }
     return true;
 }
function db_selectrecord($nome, $record, $dbcadastro, $db_opcao = 3, $js_script = "", $nomevar = "", $bgcolor = "", $todos = "", $onchange = "")
{
    if ($nomevar != "") {
        $nome = $nomevar;
        $nomedescr = $nomevar . "descr";
    } else {
        $nomedescr = $nome . "descr";
    }
    if ($db_opcao != 3 && $db_opcao != 5 && $db_opcao != 22 && $db_opcao != 33) {
        ?>
    <select name="<?php 
        echo $nome;
        ?>
" id="<?php 
        echo $nome;
        ?>
" 
	  onchange="js_ProcCod_<?php 
        echo $nome;
        ?>
('<?php 
        echo $nome;
        ?>
','<?php 
        echo $nomedescr;
        ?>
');<?php 
        echo $onchange;
        ?>
"
    <?php 
        if ($dbcadastro == true) {
            if ($db_opcao == 3 || $db_opcao == 22) {
                echo " readonly ";
            }
            if ($db_opcao == 5) {
                echo " disabled ";
            }
        }
        echo $js_script;
        ?>
     >
    <?php 
        if ($todos != "") {
            ?>
	  <option value="<?php 
            echo $todos;
            ?>
" ><?php 
            echo $todos;
            ?>
</option>
	  <?php 
        }
        for ($sqli = 0; $sqli < pg_numrows($record); $sqli++) {
            $sqlv = pg_result($record, $sqli, 0);
            ?>
      <option value="<?php 
            echo $sqlv;
            ?>
" <?php 
            echo @$GLOBALS[$nome] == $sqlv ? "selected" : "";
            ?>
><?php 
            echo $sqlv;
            ?>
</option>
      <?php 
        }
        ?>
	
    </select>
    <?php 
        if (pg_numfields($record) > 0) {
            ?>
      <select name="<?php 
            echo $nomedescr;
            ?>
" id="<?php 
            echo $nomedescr;
            ?>
" 
	  onchange="js_ProcCod_<?php 
            echo $nome;
            ?>
('<?php 
            echo $nomedescr;
            ?>
','<?php 
            echo $nome;
            ?>
');<?php 
            echo $onchange;
            ?>
"
      <?php 
            if ($dbcadastro == true) {
                if ($db_opcao == 3 || $db_opcao == 22) {
                    echo " readonly ";
                }
                if ($db_opcao == 5) {
                    echo " disabled ";
                }
            }
            echo $js_script;
            ?>
       >
      <?php 
            if ($todos != "") {
                ?>
	  <option value="<?php 
                echo $todos;
                ?>
" >Todos ...</option>
	  <?php 
            }
            for ($sqli = 0; $sqli < pg_numrows($record); $sqli++) {
                $sqlv = pg_result($record, $sqli, 0);
                $sqlv1 = pg_result($record, $sqli, 1);
                ?>
      <option value="<?php 
                echo $sqlv;
                ?>
" ><?php 
                echo $sqlv1;
                ?>
</option>
        <?php 
            }
            ?>
	
      </select>
      <script>
      function js_ProcCod_<?php 
            echo $nome;
            ?>
(proc,res) {
       var sel1 = document.form1.elements[proc];
       var sel2 = document.form1.elements[res];		  
       for(var i = 0;i < sel1.options.length;i++) {
	     if(sel1.options[sel1.selectedIndex].value == sel2.options[i].value)
	       sel2.options[i].selected = true;
	   }
      }
      //document.form1.elements['<?php 
            echo $nome;
            ?>
'].options[0].selected = true;
      js_ProcCod_<?php 
            echo $nome;
            ?>
('<?php 
            echo $nome;
            ?>
','<?php 
            echo $nomedescr;
            ?>
');
      </script>
      <?php 
        } else {
            ?>
      <script>
      function js_ProcCod_<?php 
            echo $nome;
            ?>
(){
      }
      </script>
      <?php 
        }
    } else {
        $clrot = new rotulocampo();
        $clrot->label("{$nome}");
        $tamm = "M{$nome}";
        db_input($nome, $GLOBALS[$tamm], '', $dbcadastro, 'text', 3, "", $nomevar, "");
        $nomec = "";
        for ($sqli = 0; $sqli < pg_numrows($record); $sqli++) {
            if (pg_result($record, $sqli, 0) == @$GLOBALS[$nome]) {
                $nomec = pg_fieldname($record, 1);
                global ${$nomec};
                ${$nomec} = pg_result($record, $sqli, 1);
                $clrot->label($nomec);
                $tamm = "M" . trim($nomec);
                break;
            }
        }
        if (!empty($nomec)) {
            db_input($nomec, $GLOBALS[$tamm], '', $dbcadastro, 'text', 3, "");
        }
    }
}
        $Llabel = "L{$campo}";
        echo "   <td class='cabec' " . ($cabecnowrap == "true" ? "nowrap" : "") . " title='" . ${$Tlabel} . "'>" . str_replace(":", "", ${$Llabel}) . "</td>\n";
    }
    echo "    <td class='cabec' title='Alterar ou Excluir'><b>Opções</b></td>";
    echo "   </tr>";
    $cabec = true;
} elseif (!$numrows > 0) {
    echo $msg_vazio;
}
if (isset($cabec) && $cabec == true) {
    for ($i = 0; $i < $numrows; $i++) {
        db_fieldsmemory($result, $i, true);
        echo "   <tr>";
        $naomostra = false;
        for ($w = 0; $w < $numcolunas; $w++) {
            $campo = trim(pg_fieldname($result, $w));
            for ($ww = 1; $ww < sizeof($quais_chaves); $ww++) {
                $valorchave = "x_" . $quais_chaves[$ww];
                $nomechave = $quais_chaves[$ww];
                $valorchave = ${$valorchave};
                if ($valorchave != null && $valorchave != "") {
                    if ($valorchave == ${$campo} && $nomechave == $campo && ($db_opcao == 2 || $db_opcao == 22 || $db_opcao == 3 || $db_opcao == 33)) {
                        $naomostra = true;
                    }
                }
            }
        }
        if ($naomostra == true) {
            continue;
        }
        for ($w = 0; $w < $numcolunas; $w++) {
Example #19
0
 /**
  * Returns information about a table or a result set
  *
  * NOTE: doesn't support table name and flags if called from a db_result
  *
  * @param  mixed $resource PostgreSQL result identifier or table name
  * @param  int $mode A valid tableInfo mode (DB_TABLEINFO_ORDERTABLE or
  *                   DB_TABLEINFO_ORDER)
  *
  * @return array An array with all the information
  */
 function tableInfo($result, $mode = null)
 {
     $count = 0;
     $id = 0;
     $res = array();
     /*
      * depending on $mode, metadata returns the following values:
      *
      * - mode is false (default):
      * $result[]:
      *   [0]["table"]  table name
      *   [0]["name"]   field name
      *   [0]["type"]   field type
      *   [0]["len"]    field length
      *   [0]["flags"]  field flags
      *
      * - mode is DB_TABLEINFO_ORDER
      * $result[]:
      *   ["num_fields"] number of metadata records
      *   [0]["table"]  table name
      *   [0]["name"]   field name
      *   [0]["type"]   field type
      *   [0]["len"]    field length
      *   [0]["flags"]  field flags
      *   ["order"][field name]  index of field named "field name"
      *   The last one is used, if you have a field name, but no index.
      *   Test:  if (isset($result['meta']['myfield'])) { ...
      *
      * - mode is DB_TABLEINFO_ORDERTABLE
      *    the same as above. but additionally
      *   ["ordertable"][table name][field name] index of field
      *      named "field name"
      *
      *      this is, because if you have fields from different
      *      tables with the same field name * they override each
      *      other with DB_TABLEINFO_ORDER
      *
      *      you can combine DB_TABLEINFO_ORDER and
      *      DB_TABLEINFO_ORDERTABLE with DB_TABLEINFO_ORDER |
      *      DB_TABLEINFO_ORDERTABLE * or with DB_TABLEINFO_FULL
      */
     // if $result is a string, then we want information about a
     // table without a resultset
     if (is_string($result)) {
         $id = pg_exec($this->connection, "SELECT * FROM {$result}");
         if (empty($id)) {
             return $this->pgsqlRaiseError();
         }
     } else {
         // else we want information about a resultset
         $id = $result;
         if (empty($id)) {
             return $this->pgsqlRaiseError();
         }
     }
     $count = @pg_numfields($id);
     // made this IF due to performance (one if is faster than $count if's)
     if (empty($mode)) {
         for ($i = 0; $i < $count; $i++) {
             $res[$i]['table'] = is_string($result) ? $result : '';
             $res[$i]['name'] = @pg_fieldname($id, $i);
             $res[$i]['type'] = @pg_fieldtype($id, $i);
             $res[$i]['len'] = @pg_fieldsize($id, $i);
             $res[$i]['flags'] = is_string($result) ? $this->_pgFieldflags($id, $i, $result) : '';
         }
     } else {
         // full
         $res["num_fields"] = $count;
         for ($i = 0; $i < $count; $i++) {
             $res[$i]['table'] = is_string($result) ? $result : '';
             $res[$i]['name'] = @pg_fieldname($id, $i);
             $res[$i]['type'] = @pg_fieldtype($id, $i);
             $res[$i]['len'] = @pg_fieldsize($id, $i);
             $res[$i]['flags'] = is_string($result) ? $this->_pgFieldFlags($id, $i, $result) : '';
             if ($mode & DB_TABLEINFO_ORDER) {
                 $res['order'][$res[$i]['name']] = $i;
             }
             if ($mode & DB_TABLEINFO_ORDERTABLE) {
                 $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
             }
         }
     }
     // free the result only if we were called on a table
     if (is_resource($id)) {
         @pg_freeresult($id);
     }
     return $res;
 }
function confirm($_POST)
{
    # get vars
    foreach ($_POST as $key => $value) {
        ${$key} = $value;
    }
    # validate input
    require_lib("validate");
    $v = new validate();
    $v->isOk($db, "string", 1, 20, "Invalid database.");
    # display errors, if any
    if ($v->isError()) {
        $theseErrors = "";
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $theseErrors .= "<li class=err>" . $e["msg"];
        }
        $theseErrors .= "<p><input type=button onClick='JavaScript:history.back();' value='&laquo; Correct submission'>";
        return $theseErrors;
    }
    # connect to db
    db_conn($db);
    # ???? SQL (uppercase all the stupid sql keywords (\s space) ????
    $sql = str_replace("\\", "", $sql);
    $sql = preg_replace("/select\\s/i", "SELECT ", $sql);
    $sql = preg_replace("/\\sfrom\\s/i", " FROM ", $sql);
    $sql = preg_replace("/delete\\s/i", "DELETE ", $sql);
    $sql = preg_replace("/\\swhere\\s/i", " WHERE ", $sql);
    $sql = preg_replace("/\\sand\\s/i", " AND ", $sql);
    $sql = preg_replace("/\\sor\\s/i", " OR ", $sql);
    $sql = preg_replace("/\\slike\\s/i", " LIKE ", $sql);
    $sql = preg_replace("/\\sasc/i", " ASC", $sql);
    $sql = preg_replace("/\\sdesc/i", " DESC", $sql);
    $sql = preg_replace("/\\sby\\s/i", " BY ", $sql);
    $sql = preg_replace("/\\sorder\\s/i", " ORDER ", $sql);
    $sql = preg_replace("/\\slimit\\s/i", " LIMIT ", $sql);
    $sql = preg_replace("/update\\s/i", "UPDATE ", $sql);
    $sql = preg_replace("/\\sset\\s/i", " SET ", $sql);
    $sql = preg_replace("/\\svalues/i", " VALUES ", $sql);
    $Rs = db_exec($sql) or die("Unable to access Cubit {$db}.");
    $fldnum = pg_numfields($Rs);
    for ($i = 0; $i < $fldnum; $i++) {
        $flds[$i] = pg_fieldname($Rs, $i);
    }
    $confirm = "<center><h3>Result Analysis</h3>\r\n        <h4>Database: {$db} </h4>\r\n        <table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "'>\r\n                <tr><th colspan={$fldnum} align=center>Sql [ " . pg_numrows($Rs) . " rows affected ]</th></tr>\r\n                <tr class='" . bg_class() . "'><td colspan={$fldnum} align=center>{$sql};</td></tr>\r\n                <tr><td colspan={$fldnum}><br></td></tr>";
    foreach ($flds as $key => $value) {
        $confirm .= "<th>{$value}</th>";
    }
    $confirm .= "</tr>";
    //List the produced Data
    $i = 0;
    if (pg_numrows($Rs) > 0) {
        while ($data = pg_fetch_array($Rs)) {
            $confirm .= "<tr class='" . bg_class() . "'>";
            foreach ($flds as $key => $value) {
                $confirm .= "<td>{$data[$value]}</td>";
            }
            $confirm .= "</tr>";
            $i++;
        }
    } else {
        $confirm .= "<tr class='" . bg_class() . "'><td colspan={$fldnum} align=center>There are results for you query</td></tr>";
    }
    $confirm .= "</table>\r\n        <form action='" . SELF . "' method=post>\r\n        <input type=hidden name=key value=confirm>\r\n        <a name='down'>\r\n        <table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "'>\r\n                <tr><td colspan=2><hr></td></tr>\r\n                <tr class='bg-even'><td>SQL</td><td><input type=text size=60 name=sql value='{$sql}'></td></tr>\r\n                <tr class='bg-odd'><td>Database</td><td><input type=text size=20 name=db value='{$db}'></td></tr>\r\n                <tr><td align=right colspan=2><input type=submit value='Exec &raquo'></td></tr>\r\n                <tr><td colspan=2><hr></td></tr>\r\n        </table>\r\n        </form><br><br><br>";
    return $confirm;
}
Example #21
0
 function sql_fieldname($offset, $query_id = 0)
 {
     if (!$query_id) {
         $query_id = $this->query_result;
     }
     return $query_id ? @pg_fieldname($query_id, $offset) : false;
 }
function db_sel_instit($instit = null, $campos = " * ")
{
    if ($instit == null || trim($instit) == "") {
        $instit = db_getsession("DB_instit");
    }
    if (trim($campos) == "") {
        $campos = " * ";
    }
    $record_config = db_query("select " . $campos . "\n                            from db_config\n                                 left join db_tipoinstit on db21_codtipo = db21_tipoinstit\n                            where codigo = " . $instit);
    if ($record_config == false) {
        return false;
    } else {
        $num_rows = pg_numrows($record_config);
        if ($num_rows > 0) {
            $num_cols = pg_numfields($record_config);
            for ($index = 0; $index < $num_cols; $index++) {
                $nam_campo = pg_fieldname($record_config, $index);
                global ${$nam_campo};
                ${$nam_campo} = pg_result($record_config, 0, $nam_campo);
            }
        }
    }
    return $num_rows;
}
 function field_name($result, $int)
 {
     $fieldname = pg_fieldname($result, $int);
     return $fieldname;
 }
Example #24
0
<?php

include 'config.inc';
$db = pg_connect($conn_str);
$result = pg_exec("SELECT * FROM " . $table_name);
pg_numrows($result);
pg_numfields($result);
pg_fieldname($result, 0);
pg_fieldsize($result, 0);
pg_fieldtype($result, 0);
pg_fieldprtlen($result, 0);
pg_fieldisnull($result, 0);
pg_result($result, 0, 0);
$result = pg_exec("INSERT INTO " . $table_name . " VALUES (7777, 'KKK')");
$oid = pg_getlastoid($result);
pg_freeresult($result);
pg_errormessage();
$result = pg_exec("UPDATE " . $table_name . " SET str = 'QQQ' WHERE str like 'RGD';");
pg_cmdtuples($result);
echo "OK";
function nomecampo_query($query, $num)
{
    $risul = pg_fieldname($query, $num);
    return $risul;
}
function db_sel_cfpess($anofolha = null, $mesfolha = null, $campos = " * ")
{
    if ($anofolha == null || trim($anofolha) == "") {
        $anofolha = db_anofolha();
    }
    if ($mesfolha == null || trim($mesfolha) == "") {
        $mesfolha = db_mesfolha();
    }
    if (trim($campos) == "") {
        $campos = " * ";
    }
    $record_cfpess = pg_exec("select " . $campos . " from cfpess where r11_anousu = " . $anofolha . " and r11_mesusu = " . $mesfolha . " and r11_instit = " . DB_getsession("DB_instit"));
    if ($record_cfpess == false) {
        return false;
    } else {
        $num_cols = pg_numfields($record_cfpess);
        $num_rows = pg_numrows($record_cfpess);
        for ($index = 0; $index < $num_cols; $index++) {
            $nam_campo = pg_fieldname($record_cfpess, $index);
            global ${$nam_campo};
            //      echo "<BR> nam_campo --> $nam_campo";
            ${$nam_campo} = @pg_result($record_cfpess, 0, $nam_campo);
        }
        return $num_rows;
    }
}
 function &FetchField($fieldOffset = 0)
 {
     $off = $fieldOffset;
     // offsets begin at 0
     $o = new ADOFieldObject();
     $o->name = @pg_fieldname($this->_queryID, $off);
     $o->type = @pg_fieldtype($this->_queryID, $off);
     $o->max_length = @pg_fieldsize($this->_queryID, $off);
     //print_r($o);
     //print "off=$off name=$o->name type=$o->type len=$o->max_length<br>";
     return $o;
 }
Example #28
0
 function Field($num = 0)
 {
     if ($this->result) {
         if (version_compare(phpversion(), "4.2.0", "ge") > 0) {
             return pg_field_name($this->result, $num);
         } else {
             return pg_fieldname($this->result, $num);
         }
     } else {
         return 0;
     }
 }
 function &FetchField($off = 0)
 {
     // offsets begin at 0
     $o = new ADOFieldObject();
     $o->name = @pg_fieldname($this->_queryID, $off);
     $o->type = @pg_fieldtype($this->_queryID, $off);
     $o->max_length = @pg_fieldsize($this->_queryID, $off);
     return $o;
 }
Example #30
0
 function sql_fieldname($offset, $query_id = 0)
 {
     $mtime = microtime();
     $mtime = explode(" ", $mtime);
     $mtime = $mtime[1] + $mtime[0];
     $starttime = $mtime;
     if (!$query_id) {
         $query_id = $this->query_result;
     }
     $mtime = microtime();
     $mtime = explode(" ", $mtime);
     $mtime = $mtime[1] + $mtime[0];
     $endtime = $mtime;
     $this->sql_time += $endtime - $starttime;
     return $query_id ? @pg_fieldname($query_id, $offset) : false;
 }