* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: BaseDB.php,v 1.8 2003/01/18 06:38:37 chriskl Exp $
+ * $Id: BaseDB.php,v 1.9 2003/01/27 15:18:03 chriskl Exp $
*/
include_once('classes/database/ADODB_base.php');
}
}
+ /**
+ * Generates the SQL for the 'select' function
+ * @param $table The table from which to select
+ * @param $show An array of columns to show
+ * @param $values An array mapping columns to values
+ * @param $nulls An array of columns that are null
+ * @return The SQL query
+ */
+ function getSelectSQL($table, $show, $values, $nulls) {
+ $this->fieldClean($table);
+
+ $sql = "SELECT \"" . join('","', $show) . "\" FROM \"{$table}\"";
+
+ // If we have values specified, add them to the WHERE clause
+ $first = true;
+ if (sizeof($values) > 0) {
+ foreach ($values as $k => $v) {
+ if ($v != '' && !in_array($k, $nulls)) {
+ if ($first) {
+ $this->fieldClean($k);
+ $this->clean($v);
+ // @@ FIX THIS QUOTING
+ $sql .= " WHERE \"{$k}\"='{$v}'";
+ $first = false;
+ } else {
+ $sql .= " AND \"{$k}\"='{$v}'";
+ }
+ }
+ }
+ }
+
+ // If we have NULL values specified, add them to the WHERE clause
+ if (sizeof($nulls) > 0) {
+ foreach ($nulls as $v) {
+ if ($first) {
+ $this->fieldClean($k);
+ $sql .= " WHERE \"{$k}\" IS NULL";
+ $first = false;
+ } else {
+ $sql .= " AND \"{$k}\" IS NULL";
+ }
+ }
+ }
+
+ return $sql;
+ }
+
/**
* Returns a recordset of all columns in a relation. Used for data export.
* @@ Note: Really needs to use a cursor
* @param $return_desc The return link name
* @param $page The current page
*
- * $Id: display.php,v 1.2 2003/01/27 14:09:51 chriskl Exp $
+ * $Id: display.php,v 1.3 2003/01/27 15:18:03 chriskl Exp $
*/
// Include application functions
include_once('conf/config.inc.php');
+ global $strQueryResults, $guiMaxRows, $strRows;
+
$action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
$PHP_SELF = $_SERVER['PHP_SELF'];
/**
* List tables in a database
*
- * $Id: tables.php,v 1.3 2003/01/25 23:59:08 slubek Exp $
+ * $Id: tables.php,v 1.4 2003/01/27 15:18:03 chriskl Exp $
*/
// Include application functions
global $localData, $database, $misc;
global $strField, $strType, $strNull, $strFunction, $strValue, $strTables, $strSelect;
global $strShow, $strInvalidParam, $strCancel, $strRowInserted, $strRowInsertedBad;
- global $strSave;
+ global $strSave, $strBack, $strSelectNeedsCol;
global $PHP_SELF;
if ($confirm) {
echo "<table>\n<tr>";
// Output table header
- echo "<tr><th class=data>{$strShow}</th><th class=data>{$strField}</th><th class=data>{$strType}</th><th class=data>{$strNull}</th><th class=data>{$strFunction}</th><th class=data>{$strValue}</th></tr>";
+ echo "<tr><th class=data>{$strShow}</th><th class=data>{$strField}</th><th class=data>{$strType}</th><th class=data>{$strNull}</th><th class=data>{$strValue}</th></tr>";
$i = 0;
while (!$attrs->EOF) {
isset($_REQUEST['nulls'][$attrs->f['attname']]) ? ' checked' : '', "></td>";
else
echo " </td>";
- echo "<td class=data{$id} nowrap><input size=10 name=\"function[{$attrs->f['attname']}]\"></td>";
echo "<td class=data{$id} nowrap>", $localData->printField("values[{$attrs->f['attname']}]",
$_REQUEST['values'][$attrs->f['attname']], $attrs->f['type']), "</td>";
echo "</tr>\n";
echo "</form>\n";
}
else {
+ if (!isset($_POST['show'])) $_POST['show'] = array();
if (!isset($_POST['values'])) $_POST['values'] = array();
if (!isset($_POST['nulls'])) $_POST['nulls'] = array();
- $localData->getSelectSQL($query, $count);
-
- $status = $localData->selectRows($_POST['table'], $_POST['values'], $_POST['nulls']);
- if ($status == 0) {
- // @@ This test here is sort of dodgy!
- if ($_POST['choice'] == $strSave)
- doDefault($strRowInserted);
- else {
- $_REQUEST['values'] = array();
- $_REQUEST['nulls'] = array();
- doInsertRow(true, $strRowInserted);
- }
+
+ if (sizeof($_POST['show']) == 0)
+ doSelectRows(true, $strSelectNeedsCol);
+ else {
+ // Generate query SQL
+ $query = $localData->getSelectSQL($_REQUEST['table'], array_keys($_POST['show']),
+ $_POST['values'], array_keys($_POST['nulls']));
+ $_REQUEST['query'] = $query;
+ $_REQUEST['return_url'] = "tables.php?action=confselectrows&{$misc->href}&table={$_REQUEST['table']}";
+ $_REQUEST['return_desc'] = $strBack;
+
+ include('display.php');
+ exit;
}
- else
- doInsertRow(true, $strRowInsertedBad);
}
}