2011-03-03 Miguel de Dios <miguel.dedios@artica.es>

* include/db/postgresql.php, include/db/mysql.php, include/functions_db.php:
	fixed the function "get_db_all_rows_filter" for PostgreSQL engine, added
	new function "get_db_last_error" and derivate functions in DB engines. And
	added new parameter $status in function "process_sql".
	
	* extensions/dbmanager.php, general/error_authconfig.php,
	general/error_dbconfig.php, godmode/groups/modu_group_list.php,
	godmode/groups/group_list.php, godmode/db/db_sanity.php,
	godmode/agentes/fields_manager.php,
	godmode/agentes/manage_config_remote.php, godmode/servers/recon_script.php,
	godmode/servers/plugin.php, godmode/modules/module_list.php,
	godmode/modules/manage_network_components_form_wmi.php,
	godmode/reporting/graphs.php: changed the calls to mysql functions to own
	functions, and rewrote some parts of source code for this action.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4057 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2011-03-03 18:35:37 +00:00
parent fbc02682cc
commit e3cf87c00f
17 changed files with 312 additions and 153 deletions

View File

@ -1,3 +1,19 @@
2011-03-03 Miguel de Dios <miguel.dedios@artica.es>
* include/db/postgresql.php, include/db/mysql.php, include/functions_db.php:
fixed the function "get_db_all_rows_filter" for PostgreSQL engine, added
new function "get_db_last_error" and derivate functions in DB engines. And
added new parameter $status in function "process_sql".
* extensions/dbmanager.php, general/error_authconfig.php,
general/error_dbconfig.php, godmode/groups/modu_group_list.php,
godmode/groups/group_list.php, godmode/db/db_sanity.php,
godmode/agentes/fields_manager.php,
godmode/agentes/manage_config_remote.php, godmode/servers/recon_script.php,
godmode/servers/plugin.php, godmode/modules/module_list.php,
godmode/modules/manage_network_components_form_wmi.php,
godmode/reporting/graphs.php: changed the calls to mysql functions to own
functions, and rewrote some parts of source code for this action.
2011-03-03 Miguel de Dios <miguel.dedios@artica.es>
* godmode/setup/news.php, godmode/setup/links.php, include/fgraph.php,
operation/agentes/status_monitor.php, operation/reporting/graph_viewer.php:

View File

@ -14,35 +14,64 @@
function dbmanager_query ($sql, &$error) {
global $config;
$retval = array();
if ($sql == '')
return false;
switch ($config["dbtype"]) {
case "mysql":
$retval = array();
$sql = html_entity_decode($sql, ENT_QUOTES);
$result = mysql_query ($sql);
if ($result === false) {
$backtrace = debug_backtrace ();
$error = mysql_error ();
return false;
if ($sql == '')
return false;
$sql = html_entity_decode($sql, ENT_QUOTES);
$result = mysql_query ($sql);
if ($result === false) {
$backtrace = debug_backtrace ();
$error = mysql_error ();
return false;
}
if ($result === true) {
return mysql_affected_rows ();
}
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {
array_push ($retval, $row);
}
mysql_free_result ($result);
if (! empty ($retval))
return $retval;
//Return false, check with === or !==
return "Empty";
break;
case "postgresql":
$retval = array();
if ($sql == '')
return false;
$sql = html_entity_decode($sql, ENT_QUOTES);
$result = process_sql($sql, "affected_rows", '', false, $status);
//$result = mysql_query ($sql);
if ($result === false) {
$backtrace = debug_backtrace();
$error = get_db_last_error();
return false;
}
if ($status == 2) {
return $result;
}
else {
return $result;
}
break;
}
if ($result === true) {
return mysql_affected_rows ();
}
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {
array_push ($retval, $row);
}
mysql_free_result ($result);
if (! empty ($retval))
return $retval;
//Return false, check with === or !==
return "Empty";
}
@ -50,6 +79,7 @@ function dbmgr_extension_main () {
require_css_file ('dbmanager', 'extensions/dbmanager/');
global $config;
if (! check_acl ($config['id_user'], 0, "PM") && ! is_user_admin ($config['id_user'])) {
pandora_audit("ACL Violation", "Trying to access Setup Management");
require ("general/noaccess.php");

View File

@ -42,7 +42,10 @@
Cannot connect to the database, please check your database setup in the <b>include/config.php</b> file or read the documentation on how to setup Pandora FMS.<i><br /><br />
Probably one or more of your user, database or hostname values are incorrect or
the database server is not running.</i><br /><br /><span class="error">
<b>MySQL ERROR:</b> <?php echo mysql_error() ?></span>
<b>DB ERROR:</b>
<?php
echo get_db_last_error();
?></span>
</div>
<div class="msg">
If you have modified auth system, problem could be because Pandora cannot override authorization variables from the config database. Remove them from your database by executing:<br><br><pre>DELETE FROM tconfig WHERE token = "auth";</pre>

View File

@ -42,7 +42,7 @@
Cannot connect to the database, please check your database setup in the <b>include/config.php</b> file or read the documentation on how to setup Pandora FMS.<i><br /><br />
Probably one or more of your user, database or hostname values are incorrect or
the database server is not running.</i><br /><br /><span class="error">
<b>MySQL ERROR:</b> '. mysql_error().'</span>
<b>DB ERROR:</b><?php echo get_db_last_error(); ?></span>
<br />&nbsp;
</div>
</div>

View File

@ -19,10 +19,11 @@ global $config;
check_login();
if (! check_acl($config['id_user'], 0, "PM")) {
if (!check_acl($config['id_user'], 0, "PM")) {
pandora_audit("ACL Violation",
"Trying to access Group Management");
require ("general/noaccess.php");
return;
}
@ -40,44 +41,43 @@ $display_on_front = (int) get_parameter ('display_on_front', 0);
if ($create_field) {
/*Check if name field is empty*/
if ($name != "") {
$sql = sprintf ('INSERT INTO tagent_custom_fields (name, display_on_front)
VALUES ("%s", "%d")',
$name, $display_on_front);
$result = mysql_query ($sql);
} else {
$result = process_sql_insert('tagent_custom_fields', array('name' => $name, 'display_on_front' => $display_on_front));
}
else {
$result = false;
}
if ($result) {
echo "<h3 class='suc'>".__('Field successfully created')."</h3>";
} else {
echo "<h3 class='error'>".__('There was a problem creating field')."</h3>"; }
}
else {
echo "<h3 class='error'>".__('There was a problem creating field')."</h3>";
}
}
/* Update field */
if ($update_field) {
/*Check if name field is empty*/
if( $name != "") {
$sql = sprintf ('UPDATE tagent_custom_fields SET name = "%s",
display_on_front = %d
WHERE id_field = %d',
$name, $display_on_front, $id_field);
$result = process_sql ($sql);
} else {
$values = array('name' => $name, 'display_on_front' => $display_on_front);
$result = process_sql_update('tagent_custom_fields', $values, array('id_field' => $id_field));
}
else {
$result = false;
}
if ($result !== false) {
echo "<h3 class='suc'>".__('Field successfully updated')."</h3>";
} else {
}
else {
echo "<h3 class='error'>".__('There was a problem modifying field')."</h3>";
}
}
/* Delete field */
if ($delete_field) {
$sql = sprintf ('DELETE FROM tagent_custom_fields WHERE id_field = %d', $id_field);
$result = process_sql ($sql);
$result = process_sql_delete('tagent_custom_fields', array('id_field' => $id_field));
if (!$result)
echo "<h3 class='error'>".__('There was a problem deleting field')."</h3>";
@ -97,7 +97,8 @@ if ($fields) {
$table->align[1] = 'center';
$table->align[2] = 'center';
$table->data = array ();
} else {
}
else {
echo '<div class="nf">'. __('No fields defined') .'</div>';
}
@ -109,7 +110,8 @@ foreach ($fields as $field) {
if($field['display_on_front']) {
$data[1] = print_image('images/tick.png', true);
}else {
}
else {
$data[1] = print_image('images/delete.png', true);
}

View File

@ -121,8 +121,13 @@ if ((isset($_GET["operacion"])) AND ($update_group == -1) ) {
$sql1 = "SELECT * FROM tagente WHERE id_grupo IN ($grouplist) ORDER BY nombre";
echo '<select name="origen" style="width:200px">';
$result=mysql_query($sql1);
while ($row=mysql_fetch_array($result)){
$rows = get_db_all_rows_sql($sql1);
if ($rows === false) {
$rows = array();
}
foreach ($rows as $row) {
if (check_acl ($config["id_user"], $row["id_grupo"], "AR")){
$source = $config["remote_config"]."/conf/". md5($row["nombre"]).".conf";
if (file_exists($source)){
@ -142,8 +147,13 @@ if ((isset($_GET["operacion"])) AND ($update_group == -1) ) {
else
$sql1 = "SELECT * FROM tagente WHERE id_grupo IN ($grouplist) ORDER BY nombre";
$result=mysql_query($sql1);
while ($row=mysql_fetch_array($result)){
$rows = get_db_all_rows_sql($sql1);
if ($rows === false) {
$rows = array();
}
foreach ($rows as $row) {
if (check_acl ($config["id_user"], $row["id_grupo"], "AW"))
echo "<option value=".$row["id_agente"].">".$row["nombre"]."</option>";
}

View File

@ -33,9 +33,13 @@ $sanity = get_parameter ("sanity", 0);
if ($sanity == 1) {
// Create tagente estado when missing
echo "<h2>".__('Checking tagente_estado table')."</h2>";
$sql = "SELECT * FROM tagente_modulo";
$result = mysql_query ($sql);
while ($row = mysql_fetch_array ($result)) {
$rows = get_db_all_rows_in_table('tagente_modulo');
if ($rows === false) {
$rows = array();
}
foreach ($rows as $row) {
$id_agente_modulo = $row[0];
$id_agente = $row["id_agente"];
// check if exist in tagente_estado and create if not
@ -50,35 +54,46 @@ if ($sanity == 1) {
}
echo "<h3>".__('Checking database consistency')."</h2>";
$query1 = "SELECT * FROM tagente_estado";
$result = mysql_query($query1);
while ($row = mysql_fetch_array ($result)) {
$id_agente_modulo = $row[1];
$rows = get_db_all_rows_in_table('tagente_estado');
if ($rows === false) {
$rows = array();
}
foreach ($rows as $row) {
$id_agente_modulo = $row['id_agente_modulo'];
# check if exist in tagente_estado and create if not
$query2 = "SELECT COUNT(*) FROM tagente_modulo WHERE id_agente_modulo = $id_agente_modulo";
$result2 = mysql_query ($query2);
$row2 = mysql_fetch_array ($result2);
if ($row2[0] == 0) {
$query3 = "DELETE FROM tagente_estado WHERE id_agente_modulo = $id_agente_modulo";
echo "Deleting non-existing module $id_agente_modulo in state table <br>";
mysql_query($query3);
$rows = get_db_all_rows_sql("SELECT COUNT(*) AS count FROM tagente_modulo WHERE id_agente_modulo = $id_agente_modulo");
if ($rows !== false) {
$row = reset($rows);
$count = $rows['count'];
if ($count == 0) {
echo "Deleting non-existing module $id_agente_modulo in state table <br>";
process_sql_delete('tagente_estado', array('id_agente_modulo' => $id_agente_modulo));
}
}
}
} elseif ($sanity == 2) {
}
elseif ($sanity == 2) {
echo "<h3>".__('Deleting non-init data')."</h2>";
$query1 = "SELECT * FROM tagente_estado WHERE utimestamp = 0";
$result = mysql_query ($query1);
while ($row = mysql_fetch_array ($result)) {
$id_agente_modulo = $row[1];
$rows = get_db_all_rows_filter("tagente_estado", array("utimestamp" => 0));
if ($rows === false) {
$rows = array();
}
foreach ($rows as $row) {
echo "Deleting non init module $id_agente_modulo <br>";
$sql = "DELETE FROM tagente_modulo WHERE id_agente_modulo = $id_agente_modulo";
mysql_query ($sql);
$sql = "DELETE FROM tagente_estado WHERE id_agente_modulo = $id_agente_modulo";
mysql_query ($sql);
process_sql_delete('tagente_estado', array('id_agente_modulo' => $row['id_agente_modulo']));
}
echo "Deleting bad module (id 0)<br>";
$sql = "DELETE FROM tagente_modulo WHERE id_modulo = 0";
mysql_query ($sql);
process_sql_delete('tagente_modulo', array('id_modulo' => 0));
}
echo "<br>";
@ -99,7 +114,4 @@ echo __('Delete non-initialized modules now');
echo "</a></b>";
echo "</div>";
?>

View File

@ -102,11 +102,18 @@ if ($create_group) {
/*Check if name field is empty*/
if ($name != "") {
$sql = sprintf ('INSERT INTO tgrupo (nombre, icon, parent, disabled, custom_id, id_skin)
VALUES ("%s", "%s", %d, %d, "%s", %d)',
$name, substr ($icon, 0, -4), $id_parent, $alerts_disabled, $custom_id, $skin);
$result = mysql_query ($sql);
} else {
$values = array(
'nombre' => $name,
'icon' => substr ($icon, 0, -4),
'parent' => $id_parent,
'disabled' => $alerts_disabled,
'custom_id' => $custom_id,
'id_skin' => $skin
);
$result = process_sql_insert('tgrupo', $values);
}
else {
$result = false;
}

View File

@ -64,15 +64,15 @@ if ($create_group) {
$id_parent = (int) get_parameter ('id_parent');
$alerts_disabled = (bool) get_parameter ('alerts_disabled');
$custom_id = (string) get_parameter ('custom_id');
$sql = sprintf ('INSERT INTO tmodule_group (name)
VALUES ("%s")',
$name);
$result = mysql_query ($sql);
$result = process_sql_insert('tmodule_group', array('name' => $name));
if ($result) {
echo "<h3 class='suc'>".__('Group successfully created')."</h3>";
} else {
echo "<h3 class='error'>".__('There was a problem creating group')."</h3>"; }
}
else {
echo "<h3 class='error'>".__('There was a problem creating group')."</h3>";
}
}
/* Update group */
@ -97,10 +97,8 @@ if ($update_group) {
if ($delete_group) {
$id_group = (int) get_parameter ('id_group');
// $sql = sprintf ('UPDATE tmodule_group set id_mg = 1 WHERE id_mg = %d', $id_group);
// $result = mysql_query ($sql);
$sql = sprintf ('DELETE FROM tmodule_group WHERE id_mg = %d', $id_group);
$result = mysql_query ($sql);
$result = process_sql_delete('tmodule_group', array('id_mg' => $id_group));
if (! $result)
echo "<h3 class='error'>".__('There was a problem deleting group')."</h3>";
else

View File

@ -89,8 +89,13 @@ echo '<td class="datos2">' . __('Module type') . '</td>';
echo '<td class="datos2">';
echo '<select name="tipo">';
echo '<option value="' . $type . '">' . get_moduletype_name ($type);
$result = mysql_query('SELECT id_tipo, nombre FROM ttipo_modulo WHERE categoria IN (0,1,2) ORDER BY nombre;');
while ($component = mysql_fetch_array($result)){
$rows = get_db_all_rows_sql('SELECT id_tipo, nombre FROM ttipo_modulo WHERE categoria IN (0,1,2) ORDER BY nombre;');
if ($rows === false) {
$rows = array();
}
foreach ($rows as $row) {
echo '<option value="' . $component['id_tipo'] . '">' . $component['nombre'] . '</option>';
}
echo '</select>';
@ -110,9 +115,15 @@ echo '<select name="id_module_group">';
if ($id) {
echo '<option value="' . $id_module_group . '">' . get_modulegroup_name($id_module_group);
}
$result = mysql_query('SELECT * FROM tmodule_group');
while ($component = mysql_fetch_array($result))
$rows = get_db_all_rows_in_table('tmodule_group');
if ($rows === false) {
$rows = array();
}
foreach ($rows as $row) {
echo '<option value="' . $component['id_mg'] . '">' . $component['name'] . '</option>';
}
echo '</select>';
echo '<tr>';

View File

@ -37,11 +37,15 @@ if ($update_module) {
$icon = get_parameter_post ("icon");
$category = get_parameter_post ("category");
$sql_update ="UPDATE ttipo_modulo
SET descripcion = '".$description."', categoria = '".$category."',
nombre = '".$name."', icon = '".$icon."'
WHERE id_tipo = '".$id_type."'";
$result = mysql_query($sql_update);
$values = array(
'descripcion' => $description,
'categoria' => $category,
'nombre' => $name,
'icon' => $icon
);
$result = process_sql_update('ttipo_modulo', $values, array('id_tipo' => $id_type));
if (! $result)
echo "<h3 class='error'>".__('Problem modifying module')."</h3>";
else
@ -54,14 +58,19 @@ echo "<th>".__('Icon')."</th>";
echo "<th>".__('ID')."</th>";
echo "<th>".__('Name')."</th>";
echo "<th>".__('Description')."</th>";
$sql = 'SELECT * FROM ttipo_modulo ORDER BY nombre';
$result = mysql_query ($sql);
$rows = get_db_all_rows_sql('SELECT * FROM ttipo_modulo ORDER BY nombre');
if ($rows === false) {
$rows = array();
}
$color = 0;
while ($row = mysql_fetch_array ($result)){
foreach ($rows as $row) {
if ($color == 1) {
$tdcolor = "datos";
$color = 0;
} else {
}
else {
$tdcolor = "datos2";
$color = 1;
}

View File

@ -37,16 +37,20 @@ print_page_header (__('Graphs management'), "", false, "", true);
// Delete module SQL code
if ($delete_graph) {
if (check_acl ($config['id_user'], 0, "AW")) {
$sql = "DELETE FROM tgraph_source WHERE id_graph = $id";
if ($res=mysql_query($sql))
$result = process_sql_delete("tgraph_source", array('id_graph' =>$id));
if ($result)
$result = "<h3 class=suc>".__('Successfully deleted')."</h3>";
else
$result = "<h3 class=error>".__('Not deleted. Error deleting data')."</h3>";
$sql = "DELETE FROM tgraph WHERE id_graph = $id";
if ($res=mysql_query($sql))
$result = process_sql_delete("tgraph", array('id_graph' =>$id));
if ($result)
$result = "<h3 class=suc>".__('Successfully deleted')."</h3>";
else
$result = "<h3 class=error>".__('Not deleted. Error deleting data')."</h3>";
echo $result;
}
else {

View File

@ -152,21 +152,23 @@ else {
$plugin_pass_opt = get_parameter ("form_pass_opt", "");
$plugin_plugin_type = get_parameter ("form_plugin_type", "0");
$sql_update ="UPDATE tplugin SET
name = '$plugin_name',
description = '$plugin_description',
max_timeout = '$plugin_max_timeout',
execute = '$plugin_execute',
net_dst_opt = '$plugin_net_dst_opt',
net_port_opt = '$plugin_net_port_opt',
user_opt = '$plugin_user_opt',
plugin_type = '$plugin_plugin_type',
pass_opt = '$plugin_pass_opt'
WHERE id = $plugin_id";
$result=mysql_query($sql_update);
$values = array(
'name' => $plugin_name,
'description' => $plugin_description,
'max_timeout' => $plugin_max_timeout,
'execute' => $plugin_execute,
'net_dst_opt' => $plugin_net_dst_opt,
'net_port_opt' => $plugin_net_port_opt,
'user_opt' => $plugin_user_opt,
'plugin_type' => $plugin_plugin_type,
'pass_opt' => $plugin_pass_opt);
$result =process_sql_update('tplugin', $values, array('id' => $plugin_id));
if (! $result) {
echo "<h3 class='error'>".__('Problem updating plugin')."</h3>";
} else {
}
else {
echo "<h3 class='suc'>".__('Plugin updated successfully')."</h3>";
}
}
@ -182,43 +184,57 @@ else {
$plugin_user_opt = get_parameter ("form_user_opt", "");
$plugin_pass_opt = get_parameter ("form_pass_opt", "");
$plugin_plugin_type = get_parameter ("form_plugin_type", "0");
$sql_insert ="INSERT tplugin (name, description, max_timeout, execute, net_dst_opt, net_port_opt, user_opt, pass_opt, plugin_type) VALUES ('$plugin_name', '$plugin_description', '$plugin_max_timeout', '$plugin_execute', '$plugin_net_dst_opt', '$plugin_net_port_opt', '$plugin_user_opt', '$plugin_pass_opt', $plugin_plugin_type)";
$result=mysql_query($sql_insert);
if (! $result){
$values = array(
'name' => $plugin_name,
'description' => $plugin_description,
'max_timeout' => $plugin_max_timeout,
'execute' => $plugin_execute,
'net_dst_opt' => $plugin_net_dst_opt,
'net_port_opt' => $plugin_net_port_opt,
'user_opt' => $plugin_user_opt,
'pass_opt' => $plugin_pass_opt,
'plugin_type' => $plugin_plugin_type);
$result = process_sql_insert('tplugin', $values);
if (! $result) {
echo "<h3 class='error'>".__('Problem creating plugin')."</h3>";
echo $sql_insert;
} else {
}
else {
echo "<h3 class='suc'>".__('Plugin created successfully')."</h3>";
}
}
if (isset($_GET["kill_plugin"])){ // if delete alert
$plugin_id = get_parameter ("kill_plugin", 0);
$sql_delete= "DELETE FROM tplugin WHERE id= ".$plugin_id;
$result=mysql_query($sql_delete);
$result = process_sql_delete('tplugin', array('id' => $plugin_id));
if (! $result){
echo "<h3 class='error'>".__('Problem deleting plugin')."</h3>";
} else {
}
else {
echo "<h3 class='suc'>".__('Plugin deleted successfully')."</h3>";
}
if ($plugin_id != 0){
$sql_delete2 ="DELETE FROM tagente_modulo WHERE id_plugin = ".$plugin_id;
$result=mysql_query($sql_delete2);
if ($plugin_id != 0){
$result = process_sql_delete('tagente_modulo', array('id_plugin' => $plugin_id));
}
}
// If not edition or insert, then list available plugins
$sql1='SELECT * FROM tplugin ORDER BY name';
$result=mysql_query($sql1);
if (mysql_num_rows($result) > 0){
$rows = get_db_sql('SELECT * FROM tplugin ORDER BY name');
if ($rows !== false) {
echo '<table width="730" cellspacing="4" cellpadding="4" class="databox">';
echo "<th>".__('Name')."</th>";
echo "<th>".__('Type')."</th>";
echo "<th>".__('Command')."</th>";
echo "<th>".__('Delete')."</th>";
$color = 0;
while ($row=mysql_fetch_array($result)){
foreach ($rows as $row) {
if ($color == 1){
$tdcolor = "datos";
$color = 0;

View File

@ -157,16 +157,16 @@ else {
// If not edition or insert, then list available reconscripts
$sql1='SELECT * FROM trecon_script ORDER BY name';
$result=mysql_query($sql1);
if (mysql_num_rows($result) > 0) {
$rows = get_db_all_rows_in_table('trecon_script');
if ($rows !== false) {
echo '<table width="730" cellspacing="4" cellpadding="4" class="databox">';
echo "<th>".__('Name')."</th>";
echo "<th>".__('Command')."</th>";
echo "<th>".__('Description')."</th>";
echo "<th>".__('Delete')."</th>";
$color = 0;
while ($row=mysql_fetch_array($result)){
foreach ($rows as $row) {
if ($color == 1){
$tdcolor = "datos";
$color = 0;

View File

@ -950,4 +950,13 @@ function mysql_safe_sql_string($string) {
return mysql_real_escape_string($string, $config['dbconnection']);
}
/**
* Get last error.
*
* @return string Return the string error.
*/
function mysql_get_db_last_error() {
return mysql_error();
}
?>

View File

@ -180,7 +180,7 @@ function postgresql_insert_id($dbconnection = '') {
return $result;
}
function postgresql_process_sql($sql, $rettype = "affected_rows", $dbconnection = '', $cache = true) {
function postgresql_process_sql($sql, $rettype = "affected_rows", $dbconnection = '', $cache = true, &$status = null) {
global $config;
global $sql_cache;
@ -205,7 +205,10 @@ function postgresql_process_sql($sql, $rettype = "affected_rows", $dbconnection
$result = pg_get_result($config['dbconnection']);
}
$time = microtime (true) - $start;
if ($result === false) {
$resultError = pg_result_error($result);
if (($result === false) || (!empty($resultError))) {
$backtrace = debug_backtrace ();
$error = sprintf ('%s (\'%s\') in <strong>%s</strong> on line %d',
pg_result_error($result), $sql, $backtrace[0]['file'], $backtrace[0]['line']);
@ -239,9 +242,9 @@ function postgresql_process_sql($sql, $rettype = "affected_rows", $dbconnection
else { //The query IS a select.
add_database_debug_trace ($sql, 0, $rows, array ('time' => $time));
while ($row = pg_fetch_assoc($result)) {
array_push ($retval, $row);
array_push($retval, $row);
}
if ($cache === true)
$sql_cache[$sql] = $retval;
pg_free_result ($result);
@ -595,7 +598,7 @@ function postgresql_get_db_value_sql($sql) {
*/
function postgresql_get_db_row_sql ($sql, $search_history_db = false) {
$sql .= " LIMIT 1";
$result = get_db_all_rows_sql ($sql, $search_history_db);
$result = get_db_all_rows_sql($sql, $search_history_db);
if($result === false)
return false;
@ -964,4 +967,13 @@ function postgresql_safe_sql_string($string) {
return pg_escape_string($config['dbconnection'], $string);
}
/**
* Get last error.
*
* @return string Return the string error.
*/
function postgresql_get_db_last_error() {
return pg_last_error();
}
?>

View File

@ -2267,7 +2267,7 @@ function get_db_all_rows_filter($table, $filter = array(), $fields = false, $whe
return mysql_get_db_all_rows_filter($table, $filter, $fields, $where_join, $search_history_db, $returnSQL);
break;
case "postgresql":
return postgresql_get_db_all_rows_sql($table, $filter, $fields, $where_join, $search_history_db, $returnSQL);
return postgresql_get_db_all_rows_filter($table, $filter, $fields, $where_join, $search_history_db, $returnSQL);
break;
}
}
@ -2397,17 +2397,19 @@ function clean_cache() {
* 'insert_id' will return the ID of an autoincrement value
* 'info' will return the full (debug) information of a query
*
* @param string $status The status and type of query (support only postgreSQL).
*
* @return mixed An array with the rows, columns and values in a multidimensional array or false in error
*/
function process_sql($sql, $rettype = "affected_rows", $dbconnection = '', $cache = true) {
function process_sql($sql, $rettype = "affected_rows", $dbconnection = '', $cache = true, &$status = null) {
global $config;
switch ($config["dbtype"]) {
case "mysql":
return mysql_process_sql($sql, $rettype, $dbconnection, $cache);
return @mysql_process_sql($sql, $rettype, $dbconnection, $cache);
break;
case "postgresql":
return postgresql_process_sql($sql, $rettype, $dbconnection, $cache);
return @postgresql_process_sql($sql, $rettype, $dbconnection, $cache, $status);
break;
}
}
@ -3486,4 +3488,22 @@ function user_access_to_agent ($id_agent, $mode = "AR", $id_user = false) {
$id_group = (int) get_db_value ('id_grupo', 'tagente', 'id_agente', (int) $id_agent);
return (bool) check_acl ($id_user, $id_group, $mode);
}
/**
* Get last error.
*
* @return string Return the string error.
*/
function get_db_last_error() {
global $config;
switch ($config["dbtype"]) {
case "mysql":
return mysql_get_db_last_error();
break;
case "postgresql":
return postgresql_get_db_last_error();
break;
}
}
?>