* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres.php,v 1.99 2003/05/08 15:25:58 chriskl Exp $
+ * $Id: Postgres.php,v 1.100 2003/05/11 10:39:29 chriskl Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
var $triggerExecTimes = array('BEFORE', 'AFTER');
// Foreign key actions
var $fkactions = array('NO ACTION', 'RESTRICT', 'CASCADE', 'SET NULL', 'SET DEFAULT');
+ // Function properties
+ var $funcprops = array(array('', 'ISSTRICT'), array('', 'ISCACHABLE'));
+ var $defaultprops = array('', '');
// Last oid assigned to a system object
var $_lastSystemOID = 18539;
/**
* Creates a new function.
* @param $funcname The name of the function to create
- * @param $args The array of argument types
+ * @param $args A comma separated string of types
* @param $returns The return type
* @param $definition The definition for the new function
* @param $language The language the function is written for
* @return 0 success
*/
function createFunction($funcname, $args, $returns, $definition, $language, $flags, $replace = false) {
- /*
- RE: arguments implementation It seem to me that we should be getting passed a comma delimited string
- and that we need a comma delimited string
- So why go through the array end around
- ADODB throws errors if you leave it blank, and join complaines as well
-
-
- Also I'm dropping support for the WITH option for now
- Given that there are only 3 options, this might best be implemented with hardcoding
- */
-
- $this->clean($funcname);
-// if (is_array($args)) {
-// $this->arrayClean($args);
-// }
+ $this->fieldClean($funcname);
$this->clean($args);
- $this->clean($returns);
+ $this->fieldClean($returns);
$this->clean($definition);
$this->clean($language);
-// if (is_array($flags)) {
-// $this->arrayClean($flags);
-// }
+ $this->arrayClean($flags);
$sql = "CREATE";
if ($replace) $sql .= " OR REPLACE";
$sql .= " FUNCTION \"{$funcname}\" (";
-/*
- if (sizeof($args) > 0)
- $sql .= '"' . join('", "', $args) . '"';
-*/
- if ($args)
+
+ if ($args != '')
$sql .= $args;
// For some reason, the returns field cannot have quotes...
$sql .= $definition;
$sql .= "\n'";
$sql .= " LANGUAGE \"{$language}\"";
-/*
- if (sizeof($flags) > 0)
- $sql .= ' WITH ("' . join('", "', $flags) . '")';
-*/
-
+
+ // Add flags
+ $first = true;
+ foreach ($flags as $v) {
+ // Skip default flags
+ if ($v == '') continue;
+ elseif ($first) {
+ $sql .= " WITH ({$v}";
+ $first = false;
+ }
+ else {
+ $sql .= ", {$v}";
+ }
+ }
+ // Close off WITH clause if necessary
+ if (!$first) $sql .= ")";
return $this->execute($sql);
}
* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres73.php,v 1.41 2003/05/07 06:29:54 chriskl Exp $
+ * $Id: Postgres73.php,v 1.42 2003/05/11 10:39:29 chriskl Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
'language' => array('USAGE', 'ALL PRIVILEGES'),
'schema' => array('CREATE', 'USAGE', 'ALL PRIVILEGES')
);
-
+ // Function properties
+ var $funcprops = array( array('', 'VOLATILE', 'IMMUTABLE', 'STABLE'),
+ array('', 'CALLED ON NULL INPUT', 'RETURNS NULL ON NULL INPUT', 'STRICT'),
+ array('', 'SECURITY INVOKER', 'SECURITY DEFINER'));
+ var $defaultprops = array('', '', '');
+
/**
* Constructor
* @param $host The hostname to connect to
return $this->getFunctions(true, 'trigger');
}
+ /**
+ * Creates a new function.
+ * @param $funcname The name of the function to create
+ * @param $args A comma separated string of types
+ * @param $returns The return type
+ * @param $definition The definition for the new function
+ * @param $language The language the function is written for
+ * @param $flags An array of optional flags
+ * @param $replace (optional) True if OR REPLACE, false for normal
+ * @return 0 success
+ */
+ function createFunction($funcname, $args, $returns, $definition, $language, $flags, $replace = false) {
+ $this->fieldClean($funcname);
+ $this->clean($args);
+ $this->fieldClean($returns);
+ $this->clean($definition);
+ $this->clean($language);
+ $this->arrayClean($flags);
+
+ $sql = "CREATE";
+ if ($replace) $sql .= " OR REPLACE";
+ $sql .= " FUNCTION \"{$funcname}\" (";
+
+ if ($args != '')
+ $sql .= $args;
+
+ // For some reason, the returns field cannot have quotes...
+ $sql .= ") RETURNS {$returns} AS '\n";
+ $sql .= $definition;
+ $sql .= "\n'";
+ $sql .= " LANGUAGE \"{$language}\"";
+
+ // Add flags
+ foreach ($flags as $v) {
+ // Skip default flags
+ if ($v == '') continue;
+ else $sql .= "\n{$v}";
+ }
+
+ return $this->execute($sql);
+ }
+
// Type functions
/**
/**
* Manage functions in a database
*
- * $Id: functions.php,v 1.10 2003/04/30 06:49:11 chriskl Exp $
+ * $Id: functions.php,v 1.11 2003/05/11 10:39:29 chriskl Exp $
*/
// Include application functions
if (!isset($_POST['formReturns'])) $_POST['formReturns'] = '';
if (!isset($_POST['formLanguage'])) $_POST['formLanguage'] = '';
if (!isset($_POST['formDefinition'])) $_POST['formDefinition'] = '';
+ if (!isset($_POST['formProperties'])) $_POST['formProperties'] = $data->defaultprops;
$types = &$localData->getTypes(true);
$langs = &$localData->getLanguages();
$misc->printMsg($msg);
echo "<form action=\"$PHP_SELF\" method=post>\n";
- echo "<table width=90%>\n";
- echo "<tr><th class=data>{$lang['strname']}</th>\n";
- echo "<th class=data>{$lang['strarguments']}</th>\n";
- echo "<th class=data>{$lang['strreturns']}</th>\n";
- echo "<th class=data>{$lang['strlanguage']}</th></tr>\n";
+ echo "<table>\n";
+ echo "<tr><th class=\"data\">{$lang['strname']}</th>\n";
+ echo "<th class=\"data\">{$lang['strarguments']}</th>\n";
+ echo "<th class=\"data\">{$lang['strreturns']}</th>\n";
+ echo "<th class=\"data\">{$lang['strlanguage']}</th></tr>\n";
- echo "<tr><td class=data1><input name=formFunction size={$data->_maxNameLen} maxlength={$data->_maxNameLen} value=\"",
- htmlspecialchars($_POST['formFunction']), "\"></td>\n";
+ echo "<tr><td class=\"data1\"><input name=\"formFunction\" size=\"16\" maxlength=\"{$data->_maxNameLen}\" value=\"",
+ htmlspecialchars($_POST['formFunction']), "\" /></td>\n";
- echo "<td class=data1><input name=formArguments style=\"width:100%;\" size={$data->_maxNameLen} maxlength={$data->_maxNameLen} value=\"",
- htmlspecialchars($_POST['formArguments']), "\"></td>\n";
+ echo "<td class=\"data1\"><input name=\"formArguments\" style=\"width:100%;\" size=\"16\" value=\"",
+ htmlspecialchars($_POST['formArguments']), "\" /></td>\n";
- echo "<td class=data1><select name=formReturns>\n";
+ echo "<td class=\"data1\"><select name=\"formReturns\">\n";
while (!$types->EOF) {
- echo "<option value=\"", htmlspecialchars($types->f[$data->typFields['typname']]), "\">",
+ echo "<option value=\"", htmlspecialchars($types->f[$data->typFields['typname']]), "\"",
+ ($types->f[$data->typFields['typname']] == $_POST['formReturns']) ? ' selected' : '', ">",
htmlspecialchars($types->f[$data->typFields['typname']]), "</option>\n";
$types->moveNext();
}
echo "</select>\n";
- echo "<td class=data1><select name=formLanguage>\n";
+ echo "<td class=\"data1\"><select name=\"formLanguage\">\n";
while (!$langs->EOF) {
- echo "<option value=\"", htmlspecialchars($langs->f[$data->langFields['lanname']]), "\">",
+ echo "<option value=\"", htmlspecialchars($langs->f[$data->langFields['lanname']]), "\"",
+ ($langs->f[$data->langFields['lanname']] == $_POST['formLanguage']) ? ' selected' : '', ">",
htmlspecialchars($langs->f[$data->langFields['lanname']]), "</option>\n";
$langs->moveNext();
}
echo "</select>\n";
echo "</td></tr>\n";
- echo "<tr><th class=data colspan=4>{$lang['strdefinition']}</th></tr>\n";
- echo "<tr><td class=data1 colspan=4><textarea style=\"width:100%;\" rows=20 cols=50 name=formDefinition wrap=virtual>",
+ echo "<tr><th class=\"data\" colspan=\"4\">{$lang['strdefinition']}</th></tr>\n";
+ echo "<tr><td class=\"data1\" colspan=\"4\"><textarea style=\"width:100%;\" rows=\"20\" cols=\"50\" name=\"formDefinition\" wrap=\"virtual\">",
htmlspecialchars($_POST['formDefinition']), "</textarea></td></tr>\n";
+ if (is_array($data->funcprops) && sizeof($data->funcprops) > 0) {
+ echo "<tr><th class=\"data\" colspan=\"4\">{$lang['strproperties']}</th></tr>\n";
+ echo "<tr><td class=\"data1\" colspan=\"4\">\n";
+ $i = 0;
+ foreach ($data->funcprops as $k => $v) {
+ echo "<select name=\"formProperties[{$i}]\">\n";
+ foreach ($v as $p) {
+ echo "<option value=\"", htmlspecialchars($p), "\"",
+ ($p == $_POST['formProperties'][$i]) ? ' selected' : '',
+ ">", htmlspecialchars($p), "</option>\n";
+ }
+ echo "</select><br />\n";
+ $i++;
+ }
+ }
+ echo "</td></tr>\n";
echo "</table>\n";
- echo "<input type=hidden name=action value=save_create>\n";
+ echo "<input type=\"hidden\" name=\"action\" value=\"save_create\" />\n";
echo $misc->form;
- echo "<input type=submit value=\"{$lang['strsave']}\"> <input type=reset value=\"{$lang['strreset']}\">\n";
+ echo "<input type=\"submit\" value=\"{$lang['strsave']}\" />\n";
+ echo "<input type=\"reset\" value=\"{$lang['strreset']}\" />\n";
echo "</form>\n";
- echo "<p><a class=navlink href=\"$PHP_SELF?{$misc->href}\">{$lang['strshowallfunctions']}</a></p>\n";
+ echo "<p><a class=\"navlink\" href=\"$PHP_SELF?{$misc->href}\">{$lang['strshowallfunctions']}</a></p>\n";
}
/**
function doSaveCreate() {
global $localData, $lang;
+ // Set properties to an empty array if it doesn't exist (for db's without properties)
+ if (!is_array($_POST['formProperties'])) $_POST['formProperties'] = array();
+
// Check that they've given a name and a definition
if ($_POST['formFunction'] == '') doCreate($lang['strfunctionneedsname']);
elseif ($_POST['formDefinition'] == '') doCreate($lang['strfunctionneedsdef']);
else {
- $status = $localData->createFunction($_POST['formFunction'], $_POST['formArguments'] , $_POST['formReturns'] , $_POST['formDefinition'] , $_POST['formLanguage'],0);
+ $status = $localData->createFunction($_POST['formFunction'], $_POST['formArguments'] ,
+ $_POST['formReturns'] , $_POST['formDefinition'] , $_POST['formLanguage'],
+ $_POST['formProperties'], false);
if ($status == 0)
doDefault($lang['strfunctioncreated']);
else