includes/dbal.php
author Dan
Mon, 08 Feb 2010 17:04:08 -0500
changeset 1220 fbfd6c852c89
parent 1207 044b0062e3bf
child 1227 bdac73ed481e
permissions -rw-r--r--
Fixed unescaped ampersands in "&enano_version" cache breaking
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     1
<?php
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     2
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     3
/*
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     4
 * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
1081
745200a9cc2a Fixed some upgrade bugs; added support for choosing one's own date/time formats; rebrand as 1.1.7
Dan
parents: 973
diff changeset
     5
 * Copyright (C) 2006-2009 Dan Fuhry
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     6
 *
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     7
 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     8
 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     9
 *
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    11
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    12
 */
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    13
 
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    14
function db_error_handler($errno, $errstr, $errfile = false, $errline = false, $errcontext = Array() )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    15
{
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    16
  if ( !defined('ENANO_DEBUG') )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    17
    return;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    18
  $e = error_reporting(0);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    19
  error_reporting($e);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    20
  if ( $e < $errno )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    21
    return;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    22
  $errtype = 'Notice';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    23
  switch ( $errno )
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    24
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    25
    case E_ERROR: case E_USER_ERROR: case E_CORE_ERROR: case E_COMPILE_ERROR: $errtype = 'Error'; break;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    26
    case E_WARNING: case E_USER_WARNING: case E_CORE_WARNING: case E_COMPILE_WARNING: $errtype = 'Warning'; break;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    27
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    28
  $debug = debug_backtrace();
286
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
    29
  if ( !isset($debug[0]['file']) )
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
    30
    return false;
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
    31
  $debug = $debug[0]['file'] . ', line ' . $debug[0]['line'];
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    32
  echo "<b>$errtype:</b> $errstr<br />Error source:<pre>$debug</pre>";
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    33
}
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
    34
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
    35
global $db_sql_parse_time;
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
    36
$db_sql_parse_time = 0;
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
    37
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    38
class mysql {
286
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
    39
  var $num_queries, $query_backtrace, $query_times, $query_sources, $latest_result, $latest_query, $_conn, $sql_stack_fields, $sql_stack_values, $debug;
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    40
  var $row = array();
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    41
	var $rowset = array();
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    42
  var $errhandler;
809
ae4ef502f742 DBAL: Fixed issues with die_json() and multiline responses from {mysql,pg_last}_error()
Dan
parents: 801
diff changeset
    43
  var $dbms_name = 'MySQL';
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    44
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    45
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    46
   * Get a flat textual list of queries that have been made.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    47
   */
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    48
  
286
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
    49
  function sql_backtrace()
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
    50
  {
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
    51
    return implode("\n-------------------------------------------------------------------\n", $this->query_backtrace);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    52
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    53
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    54
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    55
   * Connect to the database, but only if a connection isn't already up.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    56
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    57
  
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    58
  function ensure_connection()
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    59
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    60
    if(!$this->_conn)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    61
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    62
      $this->connect();
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    63
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    64
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    65
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    66
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    67
   * Exit Enano, dumping out a friendly error message indicating a database error on the way out.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    68
   * @param string Description or location of error; defaults to none
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    69
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    70
 
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    71
  function _die($t = '')
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    72
  {
940
645727469415 DBAL: _die() now detects installation environment and, if present, calls installer UI library for error display chrome
Dan
parents: 902
diff changeset
    73
    if ( defined('ENANO_HEADERS_SENT') )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    74
      ob_clean();
940
645727469415 DBAL: _die() now detects installation environment and, if present, calls installer UI library for error display chrome
Dan
parents: 902
diff changeset
    75
    
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    76
    $internal_text = $this->get_error($t);
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    77
    
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    78
    if ( defined('ENANO_CONFIG_FETCHED') )
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    79
      // config is in, we can show a slightly nicer looking error page
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    80
      die_semicritical('Database error', $internal_text);
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    81
    else
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    82
      // no config, display using no-DB template engine
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    83
      grinding_halt('Database error', $internal_text);
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    84
    
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    85
    exit;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    86
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    87
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    88
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    89
   * Get the internal text used for a database error message.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    90
   * @param string Description or location of error; defaults to none
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    91
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    92
  
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    93
  function get_error($t = '')
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    94
  {
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    95
    @header('HTTP/1.1 500 Internal Server Error');
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    96
    
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    97
    $bt = $this->latest_query;
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    98
    $e = htmlspecialchars($this->sql_error());
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
    99
    if ( empty($e) )
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   100
      $e = '&lt;none&gt;';
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   101
    
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   102
    global $email;
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   103
    
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   104
    // As long as the admin's e-mail is accessible, display it.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   105
    $email_info = ( defined('ENANO_CONFIG_FETCHED') && is_object($email) )
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   106
                    ? ', at &lt;' . $email->jscode() . $email->encryptEmail(getConfig('contact_email')) . '&gt;'
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   107
                    : '';
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   108
    
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   109
    $internal_text = "<h3>The site was unable to finish serving your request.</h3>
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   110
                      <p>We apologize for the inconveience, but an error occurred in the Enano database layer. Please report the full text of this page to the administrator of this site{$email_info}.</p>
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   111
                      <p>Description or location of error: $t<br />
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   112
                      Error returned by $this->dbms_name extension: $e</p>
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   113
                      <p>Most recent SQL query:</p>
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   114
                      <pre>$bt</pre>";
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   115
    return $internal_text;
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   116
  }
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   117
  
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   118
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   119
   * Exit Enano and output a JSON format datbase error.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   120
   * @param string Description or location of error; defaults to none
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   121
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   122
  
475
51386f1852b8 Fixed $db->die_json(), should now produce standards-compliant output.
Dan
parents: 468
diff changeset
   123
  function die_json($loc = false)
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   124
  {
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   125
    $e = str_replace("\n", "\\n", addslashes(htmlspecialchars($this->sql_error())));
468
194a19711346 Fixed the fact that cron just didn't work at all (brain fart that day or something)
Dan
parents: 424
diff changeset
   126
    $q = str_replace("\n", "\\n", addslashes($this->latest_query));
475
51386f1852b8 Fixed $db->die_json(), should now produce standards-compliant output.
Dan
parents: 468
diff changeset
   127
    $loc = ( $loc ) ? addslashes("\n\nDescription or location of error: $loc") : "";
51386f1852b8 Fixed $db->die_json(), should now produce standards-compliant output.
Dan
parents: 468
diff changeset
   128
    $loc .= "\n\nPlease report the full text of this error to the administrator of the site. If you believe that this is a bug with the software, please contact support@enanocms.org.";
51386f1852b8 Fixed $db->die_json(), should now produce standards-compliant output.
Dan
parents: 468
diff changeset
   129
    $loc = str_replace("\n", "\\n", $loc);
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   130
    $t = "{\"mode\":\"error\",\"error\":\"An error occurred during database query.\\nQuery was:\\n  $q\\n\\nError returned by {$this->dbms_name}: $e$loc\"}";
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   131
    die($t);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   132
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   133
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   134
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   135
   * Connect to the database.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   136
   * @param bool If true, enables all other parameters. Defaults to false, which emans that you can call this function with no arguments and it will fetch information from the config file.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   137
   * @param string Database server hostname
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   138
   * @param string Database server username
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   139
   * @param string Database server password
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   140
   * @param string Name of the database
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   141
   * @param int Optional port number to connect over
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   142
   */
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   143
  
857
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   144
  function connect($manual_credentials = false, $dbhost = false, $dbuser = false, $dbpasswd = false, $dbname = false, $dbport = false)
268
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   145
  {
483
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   146
    if ( !defined('ENANO_SQL_CONSTANTS') )
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   147
    {
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   148
      define('ENANO_SQL_CONSTANTS', '');
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   149
      define('ENANO_DBLAYER', 'MYSQL');
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   150
      define('ENANO_SQLFUNC_LOWERCASE', 'lcase');
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   151
      define('ENANO_SQL_MULTISTRING_PRFIX', '');
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   152
      define('ENANO_SQL_BOOLEAN_TRUE', 'true');
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   153
      define('ENANO_SQL_BOOLEAN_FALSE', 'false');
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   154
    }
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   155
    
322
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   156
    if ( !$manual_credentials )
268
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   157
    {
1184
2cb6d7086776 Backed out of ENANO_INSTALLED check in DBAL, it broke CLI installs badly
Dan
parents: 1175
diff changeset
   158
      if ( defined('IN_ENANO_INSTALL') && !defined('IN_ENANO_UPGRADE') )
322
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   159
      {
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   160
        @include(ENANO_ROOT.'/config.new.php');
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   161
      }
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   162
      else
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   163
      {
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   164
        @include(ENANO_ROOT.'/config.php');
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   165
      }
857
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   166
      
322
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   167
      if ( isset($crypto_key) )
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   168
        unset($crypto_key); // Get this sucker out of memory fast
857
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   169
      if ( empty($dbport) )
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   170
        $dbport = 3306;
268
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   171
      
322
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   172
      if ( !defined('ENANO_INSTALLED') && !defined('MIDGET_INSTALLED') && !defined('IN_ENANO_INSTALL') )
272
e0ec986c0af3 Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
parents: 268
diff changeset
   173
      {
322
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   174
        // scriptPath isn't set yet - we need to autodetect it to avoid infinite redirects
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   175
        if ( !defined('scriptPath') )
272
e0ec986c0af3 Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
parents: 268
diff changeset
   176
        {
322
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   177
          if ( isset($_SERVER['PATH_INFO']) && !preg_match('/index\.php$/', $_SERVER['PATH_INFO']) )
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   178
          {
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   179
            $_SERVER['REQUEST_URI'] = preg_replace(';' . preg_quote($_SERVER['PATH_INFO']) . '$;', '', $_SERVER['REQUEST_URI']);
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   180
          }
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   181
          if ( !preg_match('/\.php$/', $_SERVER['REQUEST_URI']) )
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   182
          {
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   183
            // user requested http://foo/enano as opposed to http://foo/enano/index.php
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   184
            $_SERVER['REQUEST_URI'] .= '/index.php';
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   185
          }
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   186
          $sp = dirname($_SERVER['REQUEST_URI']);
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   187
          if($sp == '/' || $sp == '\\') $sp = '';
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   188
          define('scriptPath', $sp);
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   189
          define('contentPath', "$sp/index.php?title=");
288
9a1a32bc2050 Hopefully once again fix scriptPath detection in dbal.php
Dan
parents: 286
diff changeset
   190
        }
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
   191
        $loc = scriptPath . '/install/index.php';
331
03850e101d7f NOW the installer should work.
Dan
parents: 326
diff changeset
   192
        define('IN_ENANO_INSTALL', 1);
03850e101d7f NOW the installer should work.
Dan
parents: 326
diff changeset
   193
        $GLOBALS['lang'] = new Language('eng');
03850e101d7f NOW the installer should work.
Dan
parents: 326
diff changeset
   194
        global $lang;
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
   195
        $lang->load_file('./language/english/core.json');
331
03850e101d7f NOW the installer should work.
Dan
parents: 326
diff changeset
   196
        $lang->load_file('./language/english/install.json');
322
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   197
        // header("Location: $loc");
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
   198
        redirect($loc, 'Enano not installed', 'We can\'t seem to find an Enano installation (valid config file). You will be transferred to the installation wizard momentarily...', 0);
322
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   199
        exit;
272
e0ec986c0af3 Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
parents: 268
diff changeset
   200
      }
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   201
    }
322
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   202
    
857
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   203
    if ( !$dbport )
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   204
      $dbport = 3306;
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   205
    
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   206
    if ( $dbhost && !empty($dbport) && $dbport != 3306 )
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   207
      $dbhost = '127.0.0.1';
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   208
    
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   209
    $host_line = ( preg_match('/^:/', $dbhost) ) ? $dbhost : "{$dbhost}:{$dbport}";
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   210
    
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   211
    $this->_conn = @mysql_connect($host_line, $dbuser, $dbpasswd);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   212
    unset($dbuser);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   213
    unset($dbpasswd); // Security
268
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   214
    
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
   215
    if ( !$this->_conn && !$manual_credentials )
268
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   216
    {
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   217
      grinding_halt('Enano is having a problem', '<p>Error: couldn\'t connect to MySQL.<br />'.mysql_error().'</p>');
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   218
    }
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
   219
    else if ( !$this->_conn && $manual_credentials )
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
   220
    {
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
   221
      return false;
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
   222
    }
268
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   223
    
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   224
    // Reset some variables
286
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   225
    $this->query_backtrace = array();
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   226
    $this->query_times = array();
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   227
    $this->query_sources = array();
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   228
    $this->num_queries = 0;
268
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   229
    
286
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   230
    $this->debug = ( defined('ENANO_DEBUG') );
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   231
    
973
451141c834fe Replaced the USE with a mysql_select_db() to cut out one query
Dan
parents: 953
diff changeset
   232
    $q = @mysql_select_db($dbname);
268
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   233
    
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   234
    if ( !$q )
352
9d7225c0db6d Enano's new installable installer, alpha 1. No upgrade and (in some parts) very little localization.
Dan
parents: 348
diff changeset
   235
    {
9d7225c0db6d Enano's new installable installer, alpha 1. No upgrade and (in some parts) very little localization.
Dan
parents: 348
diff changeset
   236
      if ( $manual_credentials )
9d7225c0db6d Enano's new installable installer, alpha 1. No upgrade and (in some parts) very little localization.
Dan
parents: 348
diff changeset
   237
        return false;
268
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   238
      $this->_die('The database could not be selected.');
352
9d7225c0db6d Enano's new installable installer, alpha 1. No upgrade and (in some parts) very little localization.
Dan
parents: 348
diff changeset
   239
    }
268
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   240
    
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   241
    // We're in!
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   242
    return true;
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   243
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   244
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   245
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   246
   * Make a SQL query.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   247
   * @param string Query
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   248
   * @param bool If false, skips all checks and logging stages. If you're doing a ton of queries, set this to true; in all other cases, leave at the default of false.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   249
   * @return resource or false on failure
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   250
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   251
  
424
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   252
  function sql_query($q, $log_query = true)
268
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   253
  {
286
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   254
    if ( $this->debug && function_exists('debug_backtrace') )
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   255
    {
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   256
      $backtrace = @debug_backtrace();
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   257
      if ( is_array($backtrace) )
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   258
      {
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   259
        $bt = $backtrace[0];
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   260
        if ( isset($backtrace[1]['class']) )
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   261
        {
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   262
          if ( $backtrace[1]['class'] == 'sessionManager' )
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   263
          {
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   264
            $bt = $backtrace[1];
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   265
          }
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   266
        }
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   267
        $this->query_sources[$q] = substr($bt['file'], strlen(ENANO_ROOT) + 1) . ', line ' . $bt['line'];
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   268
      }
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   269
      unset($backtrace);
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   270
    }
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   271
    
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   272
    $this->num_queries++;
424
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   273
    if ( $log_query || defined('ENANO_DEBUG') )
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   274
    {
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   275
      $this->query_backtrace[] = $q;
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   276
      $this->latest_query = $q;
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   277
    }
268
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   278
    // First make sure we have a connection
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   279
    if ( !$this->_conn )
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   280
    {
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   281
      $this->_die('A database connection has not yet been established.');
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   282
    }
424
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   283
    // Start the timer
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   284
    if ( $log_query || defined('ENANO_DEBUG') )
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   285
      $time_start = microtime_float();
268
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   286
    // Does this query look malicious?
424
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   287
    if ( $log_query || defined('ENANO_DEBUG') )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   288
    {
424
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   289
      if ( !$this->check_query($q) )
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   290
      {
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   291
        $this->report_query($q);
681
424ea7aac0ca SECURITY: Full query is no longer shown on SQL injection attempt; silenced calls to mysql_unbuffered_query() due to some untraceable yet harmless errors
Dan
parents: 636
diff changeset
   292
        $debug = ( defined('ENANO_DEBUG') ) ? '<p>Query was:</p><pre>'.htmlspecialchars($q).'</pre>' : '';
424ea7aac0ca SECURITY: Full query is no longer shown on SQL injection attempt; silenced calls to mysql_unbuffered_query() due to some untraceable yet harmless errors
Dan
parents: 636
diff changeset
   293
        grinding_halt('SQL Injection attempt', '<p>Enano has caught and prevented an SQL injection attempt. Your IP address has been recorded and the administrator has been notified.</p>' . $debug);
424
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   294
      }
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   295
    }
268
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   296
    
619
80fa6fa6bf3a Oops, somehow changed mysql_query() to pg_query() in MySQL DBAL
Dan
parents: 616
diff changeset
   297
    $r = mysql_query($q, $this->_conn);
424
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   298
    
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   299
    if ( $log_query )
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   300
      $this->query_times[$q] = microtime_float() - $time_start;
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   301
    
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   302
    $this->latest_result = $r;
424
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   303
    
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   304
    return $r;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   305
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   306
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   307
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   308
   * Make a SQL query, but do not have PHP buffer all the results. Useful for queries that are expected to return a huge number of results.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   309
   * @param string Query
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   310
   * @param bool If false, skips all checks and logging stages. If you're doing a ton of queries, set this to true; in all other cases, leave at the default of false.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   311
   * @return resource or false on failure
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   312
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   313
  
424
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   314
  function sql_unbuffered_query($q, $log_query = true)
268
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   315
  {
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   316
    $this->num_queries++;
424
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   317
    if ( $log_query || defined('ENANO_DEBUG') )
f58e0b6e9c22 Some memory usage improvements, I think. PHP is being weird to me.
Dan
parents: 374
diff changeset
   318
      $this->query_backtrace[] = '(UNBUFFERED) ' . $q;
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   319
    $this->latest_query = $q;
268
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   320
    // First make sure we have a connection
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   321
    if ( !$this->_conn )
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   322
    {
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   323
      $this->_die('A database connection has not yet been established.');
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   324
    }
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   325
    // Does this query look malicious?
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   326
    if ( !$this->check_query($q) )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   327
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   328
      $this->report_query($q);
681
424ea7aac0ca SECURITY: Full query is no longer shown on SQL injection attempt; silenced calls to mysql_unbuffered_query() due to some untraceable yet harmless errors
Dan
parents: 636
diff changeset
   329
      $debug = ( defined('ENANO_DEBUG') ) ? '<p>Query was:</p><pre>'.htmlspecialchars($q).'</pre>' : '';
424ea7aac0ca SECURITY: Full query is no longer shown on SQL injection attempt; silenced calls to mysql_unbuffered_query() due to some untraceable yet harmless errors
Dan
parents: 636
diff changeset
   330
      grinding_halt('SQL Injection attempt', '<p>Enano has caught and prevented an SQL injection attempt. Your IP address has been recorded and the administrator has been notified.</p>' . $debug);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   331
    }
268
58477ab3937f Hopefully managed to put enough hacks in there to make renaming the config file the last step, so if it fails, it can be done manually
Dan
parents: 256
diff changeset
   332
    
286
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   333
    $time_start = microtime_float();
681
424ea7aac0ca SECURITY: Full query is no longer shown on SQL injection attempt; silenced calls to mysql_unbuffered_query() due to some untraceable yet harmless errors
Dan
parents: 636
diff changeset
   334
    $r = @mysql_unbuffered_query($q, $this->_conn);
286
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   335
    $this->query_times[$q] = microtime_float() - $time_start;
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   336
    $this->latest_result = $r;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   337
    return $r;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   338
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   339
  
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   340
  /**
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   341
   * Performs heuristic analysis on a SQL query to check for known attack patterns.
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   342
   * @param string $q the query to check
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   343
   * @return bool true if query passed check, otherwise false
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   344
   */
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   345
  
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   346
  function check_query($q, $debug = false)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   347
  {
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   348
    global $db_sql_parse_time;
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   349
    $ts = microtime_float();
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   350
    
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   351
    // remove properly escaped quotes
812
68060328e9c6 Added CLI installer. Supports interactive, command-line, and internal-call installation. Fixed a few bugs related to anti-SQL injection parser and plugin installation.
Dan
parents: 809
diff changeset
   352
    $q = str_replace('\\\\', '', $q);
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   353
    $q = str_replace(array("\\\"", "\\'"), '', $q);
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   354
    
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   355
    // make sure quotes match
616
e311f5e6f904 Got the installer working. Fixed a few bugs including a nasty-to-debug issue where the lang_id was being hardcoded during installation, resulting in strings being inserted with the wrong lang_id causing an infinfinite loop with fetch() throwing a "no strings" error and using template (which calls fetch()) to complain
Dan
parents: 592
diff changeset
   356
    foreach ( array("'", '"') as $quote )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   357
    {
812
68060328e9c6 Added CLI installer. Supports interactive, command-line, and internal-call installation. Fixed a few bugs related to anti-SQL injection parser and plugin installation.
Dan
parents: 809
diff changeset
   358
      $n_quotes = get_char_count($q, $quote);
68060328e9c6 Added CLI installer. Supports interactive, command-line, and internal-call installation. Fixed a few bugs related to anti-SQL injection parser and plugin installation.
Dan
parents: 809
diff changeset
   359
      if ( $n_quotes % 2 == 1 )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   360
      {
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   361
        // mismatched quotes
812
68060328e9c6 Added CLI installer. Supports interactive, command-line, and internal-call installation. Fixed a few bugs related to anti-SQL injection parser and plugin installation.
Dan
parents: 809
diff changeset
   362
        if ( $debug ) echo "Found mismatched quotes in query; parsed:\n$q\n";
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   363
        return false;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   364
      }
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   365
      // this quote is now confirmed to be matching; we can safely move all quoted strings out and replace with a token
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   366
      $q = preg_replace("/$quote(.*?)$quote/s", 'SAFE_QUOTE', $q);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   367
    }
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   368
    $q = preg_replace("/(SAFE_QUOTE)+/", 'SAFE_QUOTE', $q);
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   369
    
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   370
    // quotes are now matched out. does this string have a comment marker in it?
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   371
    if ( strstr($q, '--') )
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   372
    {
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   373
      return false;
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   374
    }
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   375
    
128
01955bf53f96 Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
parents: 91
diff changeset
   376
    if ( preg_match('/[\s]+(SAFE_QUOTE|[\S]+)=\\1($|[\s]+)/', $q, $match) )
01955bf53f96 Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
parents: 91
diff changeset
   377
    {
01955bf53f96 Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
parents: 91
diff changeset
   378
      if ( $debug ) echo 'Found always-true test in query, injection attempt caught, match:<br />' . '<pre>' . print_r($match, true) . '</pre>';
01955bf53f96 Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
parents: 91
diff changeset
   379
      return false;
01955bf53f96 Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
parents: 91
diff changeset
   380
    }
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   381
    
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   382
    $ts = microtime_float() - $ts;
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   383
    $db_sql_parse_time += $ts;
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   384
    return true;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   385
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   386
  
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   387
  /**
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   388
   * Set the internal result pointer to X
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   389
   * @param int $pos The number of the row
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   390
   * @param resource $result The MySQL result resource - if not given, the latest cached query is assumed
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   391
   * @return true on success, false on failure
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   392
   */
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   393
   
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   394
  function sql_data_seek($pos, $result = false)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   395
  {
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   396
    if ( !$result )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   397
      $result = $this->latest_result;
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   398
    if ( !$result )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   399
      return false;
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   400
    
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   401
    return mysql_data_seek($result, $pos) ? true : false;
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   402
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   403
  
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   404
  /**
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   405
   * Reports a bad query to the admin
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   406
   * @param string $query the naughty query
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   407
   * @access private
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   408
   */
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   409
   
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   410
  function report_query($query)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   411
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   412
    global $session;
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   413
    if ( is_object($session) && defined('ENANO_MAINSTREAM') )
1175
1e2c9819ede3 Logs: Fully integrated an author_uid column. Logs are now linked by user ID instead of just username, so they survive username changes better. Database is changed. Fixes issue 6.
Dan
parents: 1165
diff changeset
   414
    {
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   415
      $username = $session->username;
1175
1e2c9819ede3 Logs: Fully integrated an author_uid column. Logs are now linked by user ID instead of just username, so they survive username changes better. Database is changed. Fixes issue 6.
Dan
parents: 1165
diff changeset
   416
      $user_id = $session->user_id;
1e2c9819ede3 Logs: Fully integrated an author_uid column. Logs are now linked by user ID instead of just username, so they survive username changes better. Database is changed. Fixes issue 6.
Dan
parents: 1165
diff changeset
   417
    }
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   418
    else
1175
1e2c9819ede3 Logs: Fully integrated an author_uid column. Logs are now linked by user ID instead of just username, so they survive username changes better. Database is changed. Fixes issue 6.
Dan
parents: 1165
diff changeset
   419
    {
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   420
      $username = 'Unavailable';
1175
1e2c9819ede3 Logs: Fully integrated an author_uid column. Logs are now linked by user ID instead of just username, so they survive username changes better. Database is changed. Fixes issue 6.
Dan
parents: 1165
diff changeset
   421
      $user_id = 1;
1e2c9819ede3 Logs: Fully integrated an author_uid column. Logs are now linked by user ID instead of just username, so they survive username changes better. Database is changed. Fixes issue 6.
Dan
parents: 1165
diff changeset
   422
    } 
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   423
    
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   424
    $query = $this->escape($query);
1175
1e2c9819ede3 Logs: Fully integrated an author_uid column. Logs are now linked by user ID instead of just username, so they survive username changes better. Database is changed. Fixes issue 6.
Dan
parents: 1165
diff changeset
   425
    $q = $this->sql_query('INSERT INTO '.table_prefix.'logs(log_type,     action,         time_id,    date_string, page_text,      author,            author_uid,       edit_summary)
1e2c9819ede3 Logs: Fully integrated an author_uid column. Logs are now linked by user ID instead of just username, so they survive username changes better. Database is changed. Fixes issue 6.
Dan
parents: 1165
diff changeset
   426
                                                     VALUES(\'security\', \'sql_inject\', '.time().', \'\',        \''.$query.'\', \''.$username.'\', ' . $user_id . ', \''.$_SERVER['REMOTE_ADDR'].'\');');
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   427
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   428
  
73
0a74676a2f2f Made the move to Loch Ness, and got some basic page grouping functionality working. TODO: fix some UI issues in Javascript ACL editor and change non-JS ACL editor to work with page groups too
Dan
parents: 21
diff changeset
   429
  /**
0a74676a2f2f Made the move to Loch Ness, and got some basic page grouping functionality working. TODO: fix some UI issues in Javascript ACL editor and change non-JS ACL editor to work with page groups too
Dan
parents: 21
diff changeset
   430
   * Returns the ID of the row last inserted.
0a74676a2f2f Made the move to Loch Ness, and got some basic page grouping functionality working. TODO: fix some UI issues in Javascript ACL editor and change non-JS ACL editor to work with page groups too
Dan
parents: 21
diff changeset
   431
   * @return int
0a74676a2f2f Made the move to Loch Ness, and got some basic page grouping functionality working. TODO: fix some UI issues in Javascript ACL editor and change non-JS ACL editor to work with page groups too
Dan
parents: 21
diff changeset
   432
   */
0a74676a2f2f Made the move to Loch Ness, and got some basic page grouping functionality working. TODO: fix some UI issues in Javascript ACL editor and change non-JS ACL editor to work with page groups too
Dan
parents: 21
diff changeset
   433
  
0a74676a2f2f Made the move to Loch Ness, and got some basic page grouping functionality working. TODO: fix some UI issues in Javascript ACL editor and change non-JS ACL editor to work with page groups too
Dan
parents: 21
diff changeset
   434
  function insert_id()
0a74676a2f2f Made the move to Loch Ness, and got some basic page grouping functionality working. TODO: fix some UI issues in Javascript ACL editor and change non-JS ACL editor to work with page groups too
Dan
parents: 21
diff changeset
   435
  {
0a74676a2f2f Made the move to Loch Ness, and got some basic page grouping functionality working. TODO: fix some UI issues in Javascript ACL editor and change non-JS ACL editor to work with page groups too
Dan
parents: 21
diff changeset
   436
    return @mysql_insert_id();
0a74676a2f2f Made the move to Loch Ness, and got some basic page grouping functionality working. TODO: fix some UI issues in Javascript ACL editor and change non-JS ACL editor to work with page groups too
Dan
parents: 21
diff changeset
   437
  }
0a74676a2f2f Made the move to Loch Ness, and got some basic page grouping functionality working. TODO: fix some UI issues in Javascript ACL editor and change non-JS ACL editor to work with page groups too
Dan
parents: 21
diff changeset
   438
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   439
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   440
   * Fetch one row from the given query as an associative array.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   441
   * @param resource The resource returned from sql_query; if this isn't provided, the last result resource is used.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   442
   * @return array
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   443
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   444
  
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   445
  function fetchrow($r = false)
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   446
  {
953
323c4cd1aa37 Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
parents: 940
diff changeset
   447
    if ( !$this->_conn )
323c4cd1aa37 Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
parents: 940
diff changeset
   448
      return false;
323c4cd1aa37 Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
parents: 940
diff changeset
   449
    
323c4cd1aa37 Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
parents: 940
diff changeset
   450
    if ( !$r )
323c4cd1aa37 Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
parents: 940
diff changeset
   451
      $r = $this->latest_result;
323c4cd1aa37 Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
parents: 940
diff changeset
   452
    
323c4cd1aa37 Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
parents: 940
diff changeset
   453
    if ( !$r )
323c4cd1aa37 Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
parents: 940
diff changeset
   454
      $this->_die('$db->fetchrow(): an invalid MySQL resource was passed.');
323c4cd1aa37 Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
parents: 940
diff changeset
   455
    
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   456
    $row = mysql_fetch_assoc($r);
953
323c4cd1aa37 Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
parents: 940
diff changeset
   457
    
770
62fed244fa1c Fixed timezone preference setting not fully implemented; added ability for users to select their own rank from a list of possible ranks based on group membership and user level
Dan
parents: 685
diff changeset
   458
    return integerize_array($row);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   459
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   460
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   461
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   462
   * Fetch one row from the given query as a numeric array.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   463
   * @param resource The resource returned from sql_query; if this isn't provided, the last result resource is used.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   464
   * @return array
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   465
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   466
  
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   467
  function fetchrow_num($r = false)
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   468
  {
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   469
    if ( !$r )
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   470
      $r = $this->latest_result;
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   471
    if ( !$r )
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   472
      $this->_die('$db->fetchrow(): an invalid MySQL resource was passed.');
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   473
    
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   474
    $row = mysql_fetch_row($r);
770
62fed244fa1c Fixed timezone preference setting not fully implemented; added ability for users to select their own rank from a list of possible ranks based on group membership and user level
Dan
parents: 685
diff changeset
   475
    return integerize_array($row);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   476
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   477
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   478
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   479
   * Get the number of results for a given query.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   480
   * @param resource The resource returned from sql_query; if this isn't provided, the last result resource is used.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   481
   * @return array
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   482
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   483
  
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   484
  function numrows($r = false)
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   485
  {
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   486
    if ( !$r )
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   487
      $r = $this->latest_result;
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   488
    if ( !$r )
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   489
      $this->_die('$db->fetchrow(): an invalid MySQL resource was passed.');
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   490
    
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   491
    return mysql_num_rows($r);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   492
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   493
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   494
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   495
   * Escape a string so that it may safely be included in a SQL query.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   496
   * @param string String to escape
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   497
   * @return string Escaped string
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   498
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   499
  
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   500
  function escape($str)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   501
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   502
    $str = mysql_real_escape_string($str);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   503
    return $str;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   504
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   505
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   506
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   507
   * Free the given result from memory. Use this when completely finished with a result resource.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   508
   * @param resource The resource returned from sql_query; if this isn't provided, the last result resource is used.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   509
   * @return null
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   510
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   511
  
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   512
  function free_result($result = false)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   513
  {
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   514
    if ( !$result )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   515
      $result = $this->latest_result;
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   516
    if ( !$result )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   517
      return null;
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   518
    
374
5c740e430a05 [minor] silenced errors to mysql_free_result() and pg_free_result()
Dan
parents: 352
diff changeset
   519
    @mysql_free_result($result);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   520
    return null;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   521
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   522
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   523
  /**
1207
044b0062e3bf DBAL: readded sql_affectedrows(), some plugins were using it
Dan
parents: 1184
diff changeset
   524
   * Returns the number of rows affected.
044b0062e3bf DBAL: readded sql_affectedrows(), some plugins were using it
Dan
parents: 1184
diff changeset
   525
   * @return int
044b0062e3bf DBAL: readded sql_affectedrows(), some plugins were using it
Dan
parents: 1184
diff changeset
   526
   */
044b0062e3bf DBAL: readded sql_affectedrows(), some plugins were using it
Dan
parents: 1184
diff changeset
   527
  
044b0062e3bf DBAL: readded sql_affectedrows(), some plugins were using it
Dan
parents: 1184
diff changeset
   528
  function sql_affectedrows()
044b0062e3bf DBAL: readded sql_affectedrows(), some plugins were using it
Dan
parents: 1184
diff changeset
   529
  {
044b0062e3bf DBAL: readded sql_affectedrows(), some plugins were using it
Dan
parents: 1184
diff changeset
   530
    return mysql_affected_rows($this->_conn);
044b0062e3bf DBAL: readded sql_affectedrows(), some plugins were using it
Dan
parents: 1184
diff changeset
   531
  }
044b0062e3bf DBAL: readded sql_affectedrows(), some plugins were using it
Dan
parents: 1184
diff changeset
   532
  
044b0062e3bf DBAL: readded sql_affectedrows(), some plugins were using it
Dan
parents: 1184
diff changeset
   533
  /**
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   534
   * Close the database connection
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   535
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   536
  
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   537
  function close()
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   538
  {
503
f205f4b201ed [minor] silence errors when closing DB connections
Dan
parents: 483
diff changeset
   539
    @mysql_close($this->_conn);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   540
    unset($this->_conn);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   541
  }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   542
  
1147
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   543
  /**
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   544
   * Get a list of columns in the given table
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   545
   * @param string Table
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   546
   * @return array
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   547
   */
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   548
  
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   549
  function columns_in($table)
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   550
  {
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   551
    if ( !is_string($table) )
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   552
      return false;
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   553
    $q = $this->sql_query("SHOW COLUMNS IN $table;");
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   554
    if ( !$q )
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   555
      $this->_die();
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   556
    
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   557
    $columns = array();
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   558
    while ( $row = $this->fetchrow_num() )
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   559
    {
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   560
      $columns[] = $row[0];
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   561
    }
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   562
    return $columns;
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   563
  }
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
   564
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   565
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   566
   * Get the text of the most recent error.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   567
   * @return string
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   568
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   569
  
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   570
  function sql_error()
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   571
	{
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
   572
    return mysql_error();
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   573
	}
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   574
  
286
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   575
  /**
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   576
   * Generates and outputs a report of all the SQL queries made during execution. Should only be called after everything's over with.
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   577
   */
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   578
  
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   579
  function sql_report()
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   580
  {
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   581
    global $db, $session, $paths, $template, $plugins; // Common objects
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   582
    if ( !$session->get_permissions('mod_misc') )
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   583
    {
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   584
      die_friendly('Access denied', '<p>You are not authorized to generate a SQL backtrace.</p>');
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   585
    }
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   586
    // Create copies of variables that may be changed after header is called
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   587
    $backtrace = $this->query_backtrace;
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   588
    $times = $this->query_times;
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   589
    $template->header();
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   590
    echo '<h3>SQL query log and timetable</h3>';
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   591
    echo '<div class="tblholder">
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   592
            <table border="0" cellspacing="1" cellpadding="4">';
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   593
    $i = 0;
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   594
    foreach ( $backtrace as $query )
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   595
    {
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   596
      $i++;
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   597
      $unbuffered = false;
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   598
      if ( substr($query, 0, 13) == '(UNBUFFERED) ' )
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   599
      {
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   600
        $query = substr($query, 13);
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   601
        $unbuffered = true;
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   602
      }
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   603
      if ( $i == 1 )
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   604
      {
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   605
        echo '<tr>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   606
                <th colspan="2">SQL backtrace for a normal page load of ' . htmlspecialchars($paths->cpage['urlname']) . '</th>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   607
              </tr>';
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   608
      }
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   609
      else
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   610
      {
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   611
        echo '<tr>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   612
                <th class="subhead" colspan="2">&nbsp;</th>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   613
              </tr>';
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   614
      }
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   615
      echo '<tr>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   616
              <td class="row2">Query:</td>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   617
              <td class="row1"><pre>' . htmlspecialchars($query) . '</pre></td>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   618
            </tr>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   619
            <tr>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   620
              <td class="row2">Time:</td>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   621
              <td class="row1">' . number_format($this->query_times[$query], 6) . ' seconds</td>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   622
            </tr>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   623
            <tr>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   624
              <td class="row2">Unbuffered:</td>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   625
              <td class="row1">' . ( $unbuffered ? 'Yes' : 'No' ) . '</td>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   626
            </tr>';
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   627
      if ( isset($this->query_sources[$query]) )
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   628
      {
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   629
        echo '<tr>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   630
                <td class="row2">Called from:</td>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   631
                <td class="row1">' . $this->query_sources[$query] . '</td>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   632
              </tr>';
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   633
      }
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   634
    }
293
3f98d4ba1e33 Added OpenDocument MIME types and extensions; make sql_report page show total time taken for SQL queries
Dan
parents: 289
diff changeset
   635
    if ( function_exists('array_sum') )
3f98d4ba1e33 Added OpenDocument MIME types and extensions; make sql_report page show total time taken for SQL queries
Dan
parents: 289
diff changeset
   636
    {
3f98d4ba1e33 Added OpenDocument MIME types and extensions; make sql_report page show total time taken for SQL queries
Dan
parents: 289
diff changeset
   637
      $query_time_total = array_sum($this->query_times);
3f98d4ba1e33 Added OpenDocument MIME types and extensions; make sql_report page show total time taken for SQL queries
Dan
parents: 289
diff changeset
   638
      echo '<tr>
3f98d4ba1e33 Added OpenDocument MIME types and extensions; make sql_report page show total time taken for SQL queries
Dan
parents: 289
diff changeset
   639
              <th class="subhead" colspan="2">
3f98d4ba1e33 Added OpenDocument MIME types and extensions; make sql_report page show total time taken for SQL queries
Dan
parents: 289
diff changeset
   640
                Total time taken for SQL queries: ' . round( $query_time_total, 6 ) . ' seconds
3f98d4ba1e33 Added OpenDocument MIME types and extensions; make sql_report page show total time taken for SQL queries
Dan
parents: 289
diff changeset
   641
              </th>
3f98d4ba1e33 Added OpenDocument MIME types and extensions; make sql_report page show total time taken for SQL queries
Dan
parents: 289
diff changeset
   642
            </tr>';
3f98d4ba1e33 Added OpenDocument MIME types and extensions; make sql_report page show total time taken for SQL queries
Dan
parents: 289
diff changeset
   643
    }
286
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   644
    echo '  </table>
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   645
          </div>';
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   646
    $template->footer();
b2f985e4cef3 Fixed a number of issues with SQL query readability and some undefined index-ish errors; consequently the SQL report feature was added
Dan
parents: 276
diff changeset
   647
  }
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   648
}
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   649
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   650
class postgresql
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   651
{
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   652
  var $num_queries, $query_backtrace, $query_times, $query_sources, $latest_result, $latest_query, $_conn, $sql_stack_fields, $sql_stack_values, $debug;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   653
  var $row = array();
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   654
	var $rowset = array();
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   655
  var $errhandler;
809
ae4ef502f742 DBAL: Fixed issues with die_json() and multiline responses from {mysql,pg_last}_error()
Dan
parents: 801
diff changeset
   656
  var $dbms_name = 'PostgreSQL';
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   657
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   658
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   659
   * Get a flat textual list of queries that have been made.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   660
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   661
  
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   662
  function sql_backtrace()
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   663
  {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   664
    return implode("\n-------------------------------------------------------------------\n", $this->query_backtrace);
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   665
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   666
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   667
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   668
   * Connect to the database, but only if a connection isn't already up.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   669
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   670
  
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   671
  function ensure_connection()
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   672
  {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   673
    if(!$this->_conn)
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   674
    {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   675
      $this->connect();
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   676
    }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   677
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   678
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   679
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   680
   * Exit Enano, dumping out a friendly error message indicating a database error on the way out.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   681
   * @param string Description or location of error; defaults to none
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   682
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   683
 
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   684
  function _die($t = '')
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   685
  {
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   686
    if ( defined('ENANO_HEADERS_SENT') )
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   687
      ob_clean();
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   688
    
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   689
    $internal_text = $this->get_error($t);
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   690
    
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   691
    if ( defined('ENANO_CONFIG_FETCHED') )
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   692
      // config is in, we can show a slightly nicer looking error page
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   693
      die_semicritical('Database error', $internal_text);
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   694
    else
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   695
      // no config, display using no-DB template engine
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   696
      grinding_halt('Database error', $internal_text);
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   697
    
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   698
    exit;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   699
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   700
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   701
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   702
   * Get the internal text used for a database error message.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   703
   * @param string Description or location of error; defaults to none
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   704
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   705
  
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   706
  function get_error($t = '')
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   707
  {
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   708
    @header('HTTP/1.1 500 Internal Server Error');
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   709
    
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   710
    $bt = $this->latest_query;
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   711
    $e = htmlspecialchars($this->sql_error());
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   712
    if ( empty($e) )
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   713
      $e = '&lt;none&gt;';
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   714
    
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   715
    global $email;
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   716
    
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   717
    // As long as the admin's e-mail is accessible, display it.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   718
    $email_info = ( defined('ENANO_CONFIG_FETCHED') && is_object($email) )
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   719
                    ? ', at &lt;' . $email->jscode() . $email->encryptEmail(getConfig('contact_email')) . '&gt;'
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   720
                    : '';
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   721
    
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   722
    $internal_text = "<h3>The site was unable to finish serving your request.</h3>
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   723
                      <p>We apologize for the inconveience, but an error occurred in the Enano database layer. Please report the full text of this page to the administrator of this site{$email_info}.</p>
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   724
                      <p>Description or location of error: $t<br />
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   725
                      Error returned by $this->dbms_name extension: $e</p>
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   726
                      <p>Most recent SQL query:</p>
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   727
                      <pre>$bt</pre>";
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   728
    return $internal_text;
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   729
  }
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   730
  
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   731
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   732
   * Exit Enano and output a JSON format datbase error.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   733
   * @param string Description or location of error; defaults to none
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   734
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   735
  
860
c931041e689a DBAL: Fixed missing $loc in pgsql die_json()
Dan
parents: 857
diff changeset
   736
  function die_json($loc = false)
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   737
  {
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   738
    $e = str_replace("\n", "\\n", addslashes(htmlspecialchars($this->sql_error())));
809
ae4ef502f742 DBAL: Fixed issues with die_json() and multiline responses from {mysql,pg_last}_error()
Dan
parents: 801
diff changeset
   739
    $q = str_replace("\n", "\\n", addslashes($this->latest_query));
ae4ef502f742 DBAL: Fixed issues with die_json() and multiline responses from {mysql,pg_last}_error()
Dan
parents: 801
diff changeset
   740
    $loc = ( $loc ) ? addslashes("\n\nDescription or location of error: $loc") : "";
ae4ef502f742 DBAL: Fixed issues with die_json() and multiline responses from {mysql,pg_last}_error()
Dan
parents: 801
diff changeset
   741
    $loc .= "\n\nPlease report the full text of this error to the administrator of the site. If you believe that this is a bug with the software, please contact support@enanocms.org.";
ae4ef502f742 DBAL: Fixed issues with die_json() and multiline responses from {mysql,pg_last}_error()
Dan
parents: 801
diff changeset
   742
    $loc = str_replace("\n", "\\n", $loc);
879
9788f2b7e08a Corrected a few display issues in Postgres DBAL. Thanks Neal.
Dan
parents: 860
diff changeset
   743
    $t = "{\"mode\":\"error\",\"error\":\"An error occurred during database query.\\nQuery was:\\n  $q\\n\\nError returned by {$this->dbms_name}: $e$loc\"}";
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   744
    die($t);
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   745
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   746
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   747
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   748
   * Connect to the database.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   749
   * @param bool If true, enables all other parameters. Defaults to false, which emans that you can call this function with no arguments and it will fetch information from the config file.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   750
   * @param string Database server hostname
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   751
   * @param string Database server username
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   752
   * @param string Database server password
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   753
   * @param string Name of the database
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   754
   * @param int Optional port number to connect over
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   755
   */
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   756
  
857
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   757
  function connect($manual_credentials = false, $dbhost = false, $dbuser = false, $dbpasswd = false, $dbname = false, $dbport = false)
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   758
  {
483
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   759
    if ( !defined('ENANO_SQL_CONSTANTS') )
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   760
    {
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   761
      define('ENANO_SQL_CONSTANTS', '');
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   762
      define('ENANO_DBLAYER', 'PGSQL');
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   763
      define('ENANO_SQLFUNC_LOWERCASE', 'lower');
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   764
      define('ENANO_SQL_MULTISTRING_PRFIX', 'E');
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   765
      define('ENANO_SQL_BOOLEAN_TRUE', '1');
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   766
      define('ENANO_SQL_BOOLEAN_FALSE', '0');
2cb1c8a6d3db Added safety against re-defining constants in dbal
Dan
parents: 475
diff changeset
   767
    }
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   768
    
322
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   769
    if ( !$manual_credentials )
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   770
    {
322
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   771
      if ( defined('IN_ENANO_INSTALL') && !defined('IN_ENANO_UPGRADE') )
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   772
      {
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   773
        @include(ENANO_ROOT.'/config.new.php');
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   774
      }
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   775
      else
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   776
      {
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   777
        @include(ENANO_ROOT.'/config.php');
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   778
      }
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   779
        
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   780
      if ( isset($crypto_key) )
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   781
        unset($crypto_key); // Get this sucker out of memory fast
857
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   782
      if ( empty($dbport) )
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   783
        $dbport = 5432;
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   784
      
322
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   785
      if ( !defined('ENANO_INSTALLED') && !defined('MIDGET_INSTALLED') && !defined('IN_ENANO_INSTALL') )
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   786
      {
322
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   787
        // scriptPath isn't set yet - we need to autodetect it to avoid infinite redirects
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   788
        if ( !defined('scriptPath') )
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   789
        {
322
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   790
          if ( isset($_SERVER['PATH_INFO']) && !preg_match('/index\.php$/', $_SERVER['PATH_INFO']) )
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   791
          {
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   792
            $_SERVER['REQUEST_URI'] = preg_replace(';' . preg_quote($_SERVER['PATH_INFO']) . '$;', '', $_SERVER['REQUEST_URI']);
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   793
          }
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   794
          if ( !preg_match('/\.php$/', $_SERVER['REQUEST_URI']) )
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   795
          {
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   796
            // user requested http://foo/enano as opposed to http://foo/enano/index.php
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   797
            $_SERVER['REQUEST_URI'] .= '/index.php';
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   798
          }
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   799
          $sp = dirname($_SERVER['REQUEST_URI']);
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   800
          if($sp == '/' || $sp == '\\') $sp = '';
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   801
          define('scriptPath', $sp);
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   802
          define('contentPath', "$sp/index.php?title=");
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   803
        }
322
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   804
        $loc = scriptPath . '/install.php';
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   805
        // header("Location: $loc");
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   806
        redirect($loc, 'Enano not installed', 'We can\'t seem to find an Enano installation (valid config file). You will be transferred to the installation wizard momentarily...', 3);
5f1cd51bf1be Many changes. Installer with PostgreSQL is broken badly and will be for some time.
Dan
parents: 320
diff changeset
   807
        exit;
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   808
      }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   809
    }
857
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   810
    
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   811
    if ( empty($dbport) )
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   812
      $dbport = 5432;
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   813
    
f3a5a276208c Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
parents: 812
diff changeset
   814
    $this->_conn = @pg_connect("host=$dbhost port=$dbport dbname=$dbname user=$dbuser password=$dbpasswd");
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   815
    unset($dbuser);
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   816
    unset($dbpasswd); // Security
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   817
    
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
   818
    if ( !$this->_conn && !$manual_credentials )
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   819
    {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   820
      grinding_halt('Enano is having a problem', '<p>Error: couldn\'t connect to PostgreSQL.<br />'.pg_last_error().'</p>');
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   821
    }
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
   822
    else if ( !$this->_conn && $manual_credentials )
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
   823
    {
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
   824
      return false;
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
   825
    }
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   826
    
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   827
    // Reset some variables
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   828
    $this->query_backtrace = array();
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   829
    $this->query_times = array();
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   830
    $this->query_sources = array();
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   831
    $this->num_queries = 0;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   832
    
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   833
    $this->debug = ( defined('ENANO_DEBUG') );
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   834
    
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   835
    // We're in!
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   836
    return true;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   837
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   838
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   839
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   840
   * Make a SQL query.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   841
   * @param string Query
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   842
   * @param bool If false, skips all checks and logging stages. If you're doing a ton of queries, set this to true; in all other cases, leave at the default of false.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   843
   * @return resource or false on failure
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   844
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   845
  
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   846
  function sql_query($q)
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   847
  {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   848
    if ( $this->debug && function_exists('debug_backtrace') )
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   849
    {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   850
      $backtrace = @debug_backtrace();
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   851
      if ( is_array($backtrace) )
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   852
      {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   853
        $bt = $backtrace[0];
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   854
        if ( isset($backtrace[1]['class']) )
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   855
        {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   856
          if ( $backtrace[1]['class'] == 'sessionManager' )
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   857
          {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   858
            $bt = $backtrace[1];
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   859
          }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   860
        }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   861
        $this->query_sources[$q] = substr($bt['file'], strlen(ENANO_ROOT) + 1) . ', line ' . $bt['line'];
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   862
      }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   863
      unset($backtrace);
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   864
    }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   865
    
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   866
    $this->num_queries++;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   867
    $this->query_backtrace[] = $q;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   868
    $this->latest_query = $q;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   869
    // First make sure we have a connection
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   870
    if ( !$this->_conn )
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   871
    {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   872
      $this->_die('A database connection has not yet been established.');
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   873
    }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   874
    // Does this query look malicious?
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   875
    if ( !$this->check_query($q) )
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   876
    {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   877
      $this->report_query($q);
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   878
      grinding_halt('SQL Injection attempt', '<p>Enano has caught and prevented an SQL injection attempt. Your IP address has been recorded and the administrator has been notified.</p><p>Query was:</p><pre>'.htmlspecialchars($q).'</pre>');
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   879
    }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   880
    
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   881
    $time_start = microtime_float();
902
e7c6f1aa7b6a Cleared up a few warnings that appeared under the Phalanger PHP interpreter.
Dan
parents: 879
diff changeset
   882
    $r = @pg_query($this->_conn, $q);
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   883
    $this->query_times[$q] = microtime_float() - $time_start;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   884
    $this->latest_result = $r;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   885
    return $r;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   886
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   887
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   888
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   889
   * Make a SQL query, but do not have PHP buffer all the results. Useful for queries that are expected to return a huge number of results.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   890
   * @param string Query
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   891
   * @param bool If false, skips all checks and logging stages. If you're doing a ton of queries, set this to true; in all other cases, leave at the default of false.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   892
   * @return resource or false on failure
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   893
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   894
  
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   895
  function sql_unbuffered_query($q)
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   896
  {
616
e311f5e6f904 Got the installer working. Fixed a few bugs including a nasty-to-debug issue where the lang_id was being hardcoded during installation, resulting in strings being inserted with the wrong lang_id causing an infinfinite loop with fetch() throwing a "no strings" error and using template (which calls fetch()) to complain
Dan
parents: 592
diff changeset
   897
    return $this->sql_query($q);
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   898
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   899
  
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   900
  /**
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   901
   * Checks a SQL query for possible signs of injection attempts
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   902
   * @param string $q the query to check
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   903
   * @return bool true if query passed check, otherwise false
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   904
   */
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   905
  
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   906
  function check_query($q, $debug = false)
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   907
  {
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   908
    global $db_sql_parse_time;
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   909
    $ts = microtime_float();
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   910
    
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   911
    // remove properly escaped quotes
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   912
    $q = str_replace(array("\\\"", "\\'"), '', $q);
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   913
    
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   914
    // make sure quotes match
616
e311f5e6f904 Got the installer working. Fixed a few bugs including a nasty-to-debug issue where the lang_id was being hardcoded during installation, resulting in strings being inserted with the wrong lang_id causing an infinfinite loop with fetch() throwing a "no strings" error and using template (which calls fetch()) to complain
Dan
parents: 592
diff changeset
   915
    foreach ( array("'", '"') as $quote )
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   916
    {
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   917
      if ( get_char_count($q, $quote) % 2 == 1 )
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   918
      {
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   919
        // mismatched quotes
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   920
        return false;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   921
      }
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   922
      // this quote is now confirmed to be matching; we can safely move all quoted strings out and replace with a token
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   923
      $q = preg_replace("/$quote(.*?)$quote/s", 'SAFE_QUOTE', $q);
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   924
    }
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   925
    $q = preg_replace("/(SAFE_QUOTE)+/", 'SAFE_QUOTE', $q);
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   926
    
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   927
    // quotes are now matched out. does this string have a comment marker in it?
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   928
    if ( strstr($q, '--') )
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   929
    {
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   930
      return false;
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   931
    }
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   932
    
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   933
    if ( preg_match('/[\s]+(SAFE_QUOTE|[\S]+)=\\1($|[\s]+)/', $q, $match) )
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   934
    {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   935
      if ( $debug ) echo 'Found always-true test in query, injection attempt caught, match:<br />' . '<pre>' . print_r($match, true) . '</pre>';
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   936
      return false;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   937
    }
592
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   938
    
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   939
    $ts = microtime_float() - $ts;
27377179fe58 Another sweep from the optimization monster.
Dan
parents: 536
diff changeset
   940
    $db_sql_parse_time += $ts;
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   941
    return true;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   942
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   943
  
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   944
  /**
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   945
   * Set the internal result pointer to X
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   946
   * @param int $pos The number of the row
879
9788f2b7e08a Corrected a few display issues in Postgres DBAL. Thanks Neal.
Dan
parents: 860
diff changeset
   947
   * @param resource $result The PostgreSQL result resource - if not given, the latest cached query is assumed
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   948
   * @return true on success, false on failure
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   949
   */
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   950
   
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   951
  function sql_data_seek($pos, $result = false)
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   952
  {
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   953
    if ( !$result )
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   954
      $result = $this->latest_result;
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   955
    if ( !$result )
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   956
      return false;
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   957
    
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
   958
    return pg_result_seek($result, $pos) ? true : false;
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   959
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   960
  
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   961
  /**
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   962
   * Reports a bad query to the admin
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   963
   * @param string $query the naughty query
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   964
   * @access private
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   965
   */
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   966
   
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   967
  function report_query($query)
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   968
  {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   969
    global $session;
1175
1e2c9819ede3 Logs: Fully integrated an author_uid column. Logs are now linked by user ID instead of just username, so they survive username changes better. Database is changed. Fixes issue 6.
Dan
parents: 1165
diff changeset
   970
    if ( is_object($session) && defined('ENANO_MAINSTREAM') )
1e2c9819ede3 Logs: Fully integrated an author_uid column. Logs are now linked by user ID instead of just username, so they survive username changes better. Database is changed. Fixes issue 6.
Dan
parents: 1165
diff changeset
   971
    {
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   972
      $username = $session->username;
1175
1e2c9819ede3 Logs: Fully integrated an author_uid column. Logs are now linked by user ID instead of just username, so they survive username changes better. Database is changed. Fixes issue 6.
Dan
parents: 1165
diff changeset
   973
      $user_id = $session->user_id;
1e2c9819ede3 Logs: Fully integrated an author_uid column. Logs are now linked by user ID instead of just username, so they survive username changes better. Database is changed. Fixes issue 6.
Dan
parents: 1165
diff changeset
   974
    }
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   975
    else
1175
1e2c9819ede3 Logs: Fully integrated an author_uid column. Logs are now linked by user ID instead of just username, so they survive username changes better. Database is changed. Fixes issue 6.
Dan
parents: 1165
diff changeset
   976
    {
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   977
      $username = 'Unavailable';
1175
1e2c9819ede3 Logs: Fully integrated an author_uid column. Logs are now linked by user ID instead of just username, so they survive username changes better. Database is changed. Fixes issue 6.
Dan
parents: 1165
diff changeset
   978
      $user_id = 1;
1e2c9819ede3 Logs: Fully integrated an author_uid column. Logs are now linked by user ID instead of just username, so they survive username changes better. Database is changed. Fixes issue 6.
Dan
parents: 1165
diff changeset
   979
    } 
1e2c9819ede3 Logs: Fully integrated an author_uid column. Logs are now linked by user ID instead of just username, so they survive username changes better. Database is changed. Fixes issue 6.
Dan
parents: 1165
diff changeset
   980
    
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   981
    $query = $this->escape($query);
1175
1e2c9819ede3 Logs: Fully integrated an author_uid column. Logs are now linked by user ID instead of just username, so they survive username changes better. Database is changed. Fixes issue 6.
Dan
parents: 1165
diff changeset
   982
    $q = $this->sql_query('INSERT INTO '.table_prefix.'logs(log_type,     action,         time_id,    date_string, page_text,      author,            author_uid,       edit_summary)
1e2c9819ede3 Logs: Fully integrated an author_uid column. Logs are now linked by user ID instead of just username, so they survive username changes better. Database is changed. Fixes issue 6.
Dan
parents: 1165
diff changeset
   983
                                                     VALUES(\'security\', \'sql_inject\', '.time().', \'\',        \''.$query.'\', \''.$username.'\', ' . $user_id . ', \''.$_SERVER['REMOTE_ADDR'].'\');');
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   984
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   985
  
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   986
  /**
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   987
   * Returns the ID of the row last inserted.
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   988
   * @return int
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   989
   */
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   990
  
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   991
  function insert_id()
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
   992
  {
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   993
    // list of primary keys in Enano tables
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   994
    // this is a bit hackish, but not much choice.
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   995
    static $primary_keys = false;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   996
    if ( !is_array($primary_keys) )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   997
    {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   998
      $primary_keys = array(
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
   999
        table_prefix . 'comments' => 'comment_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1000
        table_prefix . 'logs' => 'log_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1001
        table_prefix . 'users' => 'user_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1002
        table_prefix . 'banlist' => 'ban_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1003
        table_prefix . 'files' => 'file_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1004
        table_prefix . 'buddies' => 'buddy_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1005
        table_prefix . 'privmsgs' => 'message_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1006
        table_prefix . 'sidebar' => 'item_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1007
        table_prefix . 'hits' => 'hit_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1008
        table_prefix . 'groups' => 'group_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1009
        table_prefix . 'group_members' => 'member_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1010
        table_prefix . 'acl' => 'rule_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1011
        table_prefix . 'page_groups' => 'pg_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1012
        table_prefix . 'page_group_members' => 'pg_member_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1013
        table_prefix . 'tags' => 'tag_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1014
        table_prefix . 'lockout' => 'id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1015
        table_prefix . 'language' => 'lang_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1016
        table_prefix . 'language_strings' => 'string_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1017
        table_prefix . 'ranks' => 'rank_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1018
        table_prefix . 'captcha' => 'code_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1019
        table_prefix . 'diffiehellman' => 'key_id',
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1020
        table_prefix . 'plugins' => 'plugin_id'
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1021
      );
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1022
      // allow plugins to patch this if needed
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1023
      global $plugins;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1024
      $code = $plugins->setHook('pgsql_set_serial_list');
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1025
      foreach ( $code as $cmd )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1026
      {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1027
        eval($cmd);
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1028
      }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1029
    }
636
c9ea830a211f Fixed a few more PostgreSQL bugs with insert_id() and an issue with setting SERIAL columns manually. May break things if installed into a database without first dropping tables.
Dan
parents: 628
diff changeset
  1030
    $last_was_insert = preg_match('/^INSERT INTO ([a-z0-9_]+)/i', $this->latest_query, $match);
628
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1031
    if ( $last_was_insert )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1032
    {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1033
      // trick based on PunBB's PostgreSQL driver
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1034
      $table =& $match[1];
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1035
      if ( isset($primary_keys[$table]) )
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1036
      {
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1037
        $primary_key = "{$table}_{$primary_keys[$table]}_seq";
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1038
        $q = pg_query("SELECT CURRVAL('$primary_key');");
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1039
        return ( $q ) ? intval(@pg_fetch_result($q, 0)) : false;
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1040
      }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1041
    }
ab6f55abb17e Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Dan
parents: 619
diff changeset
  1042
    return false;
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1043
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1044
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1045
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1046
   * Fetch one row from the given query as an associative array.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1047
   * @param resource The resource returned from sql_query; if this isn't provided, the last result resource is used.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1048
   * @return array
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1049
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1050
  
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1051
  function fetchrow($r = false)
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1052
  {
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1053
    if ( !$this->_conn )
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1054
      return false;
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1055
    if ( !$r )
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1056
      $r = $this->latest_result;
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1057
    if ( !$r )
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1058
      $this->_die('$db->fetchrow(): an invalid ' . $this->dbms_name . ' resource was passed.');
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1059
    
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1060
    $row = pg_fetch_assoc($r);
770
62fed244fa1c Fixed timezone preference setting not fully implemented; added ability for users to select their own rank from a list of possible ranks based on group membership and user level
Dan
parents: 685
diff changeset
  1061
    return integerize_array($row);
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1062
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1063
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1064
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1065
   * Fetch one row from the given query as a numeric array.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1066
   * @param resource The resource returned from sql_query; if this isn't provided, the last result resource is used.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1067
   * @return array
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1068
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1069
  
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1070
  function fetchrow_num($r = false)
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1071
  {
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1072
    if ( !$r )
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1073
      $r = $this->latest_result;
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1074
    if ( !$r )
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1075
      $this->_die('$db->fetchrow(): an invalid ' . $this->dbms_name . ' resource was passed.');
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1076
    
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1077
    $row = pg_fetch_row($r);
770
62fed244fa1c Fixed timezone preference setting not fully implemented; added ability for users to select their own rank from a list of possible ranks based on group membership and user level
Dan
parents: 685
diff changeset
  1078
    return integerize_array($row);
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1079
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1080
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1081
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1082
   * Get the number of results for a given query.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1083
   * @param resource The resource returned from sql_query; if this isn't provided, the last result resource is used.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1084
   * @return array
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1085
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1086
  
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1087
  function numrows($r = false)
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1088
  {
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1089
    if ( !$r )
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1090
      $r = $this->latest_result;
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1091
    if ( !$r )
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1092
      $this->_die('$db->fetchrow(): an invalid ' . $this->dbms_name . ' resource was passed.');
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1093
    
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1094
    $n = pg_num_rows($r);
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1095
    return $n;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1096
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1097
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1098
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1099
   * Escape a string so that it may safely be included in a SQL query.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1100
   * @param string String to escape
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1101
   * @return string Escaped string
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1102
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1103
  
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1104
  function escape($str)
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1105
  {
860
c931041e689a DBAL: Fixed missing $loc in pgsql die_json()
Dan
parents: 857
diff changeset
  1106
    $str = pg_escape_string($this->_conn, $str);
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1107
    return $str;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1108
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1109
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1110
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1111
   * Free the given result from memory. Use this when completely finished with a result resource.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1112
   * @param resource The resource returned from sql_query; if this isn't provided, the last result resource is used.
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1113
   * @return null
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1114
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1115
  
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1116
  function free_result($result = false)
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1117
  {
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1118
    if ( !$result )
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1119
      $result = $this->latest_result;
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1120
    
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1121
    if ( !$result )
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1122
      return null;
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1123
    
374
5c740e430a05 [minor] silenced errors to mysql_free_result() and pg_free_result()
Dan
parents: 352
diff changeset
  1124
    @pg_free_result($result);
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1125
    return null;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1126
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1127
  
1165
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1128
  /**
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1129
   * Close the database connection
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1130
   */
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1131
  
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1132
  function close()
ce8aaa2956d1 DBAL: Majorly cleaned up and improved coding standards/documentation
Dan
parents: 1147
diff changeset
  1133
  {
503
f205f4b201ed [minor] silence errors when closing DB connections
Dan
parents: 483
diff changeset
  1134
    @pg_close($this->_conn);
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1135
    unset($this->_conn);
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1136
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1137
  
1147
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1138
  /**
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1139
   * Get a list of columns in the given table
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1140
   * @param string Table
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1141
   * @return array
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1142
   */
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1143
  
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1144
  function columns_in($table)
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1145
  {
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1146
    if ( !is_string($table) )
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1147
      return false;
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1148
    $q = $this->sql_query("SELECT * FROM $table LIMIT 1 OFFSET 0;");
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1149
    if ( !$q )
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1150
      $this->_die();
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1151
    if ( $this->numrows() < 1 )
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1152
    {
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1153
      // FIXME: Have another way to do this if the table is empty
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1154
      return false;
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1155
    }
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1156
    
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1157
    $row = $this->fetchrow();
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1158
    $this->free_result();
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1159
    return array_keys($row);
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1160
  }
7ddd475bc661 PostgreSQL: Fixed user pages. Also added a columns_in() method to the DBAL to list columns in a table
Dan
parents: 1143
diff changeset
  1161
  
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1162
	function sql_error()
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1163
	{
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1164
		if ( $this->_conn )
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1165
		{
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
  1166
			return pg_last_error();
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1167
		}
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1168
		else
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1169
		{
348
87e08a6e4fec Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents: 331
diff changeset
  1170
			return ( defined('IN_ENANO_INSTALL') ) ? $GLOBALS["lang"]->get('dbpgsql_msg_err_auth') : 'Access to the database was denied. Ensure that your database exists and that your username and password are correct.';
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1171
		}
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1172
	}
1207
044b0062e3bf DBAL: readded sql_affectedrows(), some plugins were using it
Dan
parents: 1184
diff changeset
  1173
	
044b0062e3bf DBAL: readded sql_affectedrows(), some plugins were using it
Dan
parents: 1184
diff changeset
  1174
	/**
044b0062e3bf DBAL: readded sql_affectedrows(), some plugins were using it
Dan
parents: 1184
diff changeset
  1175
   * Returns the number of rows affected.
044b0062e3bf DBAL: readded sql_affectedrows(), some plugins were using it
Dan
parents: 1184
diff changeset
  1176
   * @return int
044b0062e3bf DBAL: readded sql_affectedrows(), some plugins were using it
Dan
parents: 1184
diff changeset
  1177
   */
044b0062e3bf DBAL: readded sql_affectedrows(), some plugins were using it
Dan
parents: 1184
diff changeset
  1178
  
044b0062e3bf DBAL: readded sql_affectedrows(), some plugins were using it
Dan
parents: 1184
diff changeset
  1179
  function sql_affectedrows()
044b0062e3bf DBAL: readded sql_affectedrows(), some plugins were using it
Dan
parents: 1184
diff changeset
  1180
  {
044b0062e3bf DBAL: readded sql_affectedrows(), some plugins were using it
Dan
parents: 1184
diff changeset
  1181
    return pg_affected_rows($this->latest_result);
044b0062e3bf DBAL: readded sql_affectedrows(), some plugins were using it
Dan
parents: 1184
diff changeset
  1182
  }
320
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1183
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1184
  /**
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1185
   * Generates and outputs a report of all the SQL queries made during execution. Should only be called after everything's over with.
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1186
   */
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1187
  
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1188
  function sql_report()
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1189
  {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1190
    global $db, $session, $paths, $template, $plugins; // Common objects
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1191
    if ( !$session->get_permissions('mod_misc') )
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1192
    {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1193
      die_friendly('Access denied', '<p>You are not authorized to generate a SQL backtrace.</p>');
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1194
    }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1195
    // Create copies of variables that may be changed after header is called
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1196
    $backtrace = $this->query_backtrace;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1197
    $times = $this->query_times;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1198
    $template->header();
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1199
    echo '<h3>SQL query log and timetable</h3>';
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1200
    echo '<div class="tblholder">
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1201
            <table border="0" cellspacing="1" cellpadding="4">';
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1202
    $i = 0;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1203
    foreach ( $backtrace as $query )
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1204
    {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1205
      $i++;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1206
      $unbuffered = false;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1207
      if ( substr($query, 0, 13) == '(UNBUFFERED) ' )
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1208
      {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1209
        $query = substr($query, 13);
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1210
        $unbuffered = true;
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1211
      }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1212
      if ( $i == 1 )
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1213
      {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1214
        echo '<tr>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1215
                <th colspan="2">SQL backtrace for a normal page load of ' . htmlspecialchars($paths->cpage['urlname']) . '</th>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1216
              </tr>';
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1217
      }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1218
      else
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1219
      {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1220
        echo '<tr>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1221
                <th class="subhead" colspan="2">&nbsp;</th>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1222
              </tr>';
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1223
      }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1224
      echo '<tr>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1225
              <td class="row2">Query:</td>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1226
              <td class="row1"><pre>' . htmlspecialchars($query) . '</pre></td>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1227
            </tr>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1228
            <tr>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1229
              <td class="row2">Time:</td>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1230
              <td class="row1">' . number_format($this->query_times[$query], 6) . ' seconds</td>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1231
            </tr>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1232
            <tr>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1233
              <td class="row2">Unbuffered:</td>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1234
              <td class="row1">' . ( $unbuffered ? 'Yes' : 'No' ) . '</td>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1235
            </tr>';
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1236
      if ( isset($this->query_sources[$query]) )
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1237
      {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1238
        echo '<tr>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1239
                <td class="row2">Called from:</td>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1240
                <td class="row1">' . $this->query_sources[$query] . '</td>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1241
              </tr>';
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1242
      }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1243
    }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1244
    if ( function_exists('array_sum') )
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1245
    {
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1246
      $query_time_total = array_sum($this->query_times);
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1247
      echo '<tr>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1248
              <th class="subhead" colspan="2">
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1249
                Total time taken for SQL queries: ' . round( $query_time_total, 6 ) . ' seconds
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1250
              </th>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1251
            </tr>';
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1252
    }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1253
    echo '  </table>
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1254
          </div>';
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1255
    $template->footer();
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1256
  }
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1257
}
112debff64bd SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
parents: 317
diff changeset
  1258
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
  1259
?>