[geeklog-cvs] geeklog: updated more sql for pgsql

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Tue Jan 26 15:53:26 EST 2010


changeset 7618:1c0ea36804ac
url:  http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/1c0ea36804ac
user: stan <yankees26an at gmail.com>
date: Sat Jun 13 23:12:39 2009 -0400
description:
updated more sql for pgsql

diffstat:

 public_html/index.php            |  15 +++++++-
 public_html/lib-common.php       |  66 +++++++++++++++++++--------------
 system/databases/pgsql.class.php |   2 +
 system/lib-database.php          |   6 +++
 system/lib-story.php             |   2 +
 5 files changed, 62 insertions(+), 29 deletions(-)

diffs (227 lines):

diff -r 96929262c25b -r 1c0ea36804ac public_html/index.php
--- a/public_html/index.php	Thu Jun 04 19:21:29 2009 -0400
+++ b/public_html/index.php	Sat Jun 13 23:12:39 2009 -0400
@@ -79,11 +79,17 @@
          . "FROM {$_TABLES['stories']} AS s, {$_TABLES['users']} AS u, "
          . "{$_TABLES['topics']} AS t WHERE (s.uid = u.uid) AND (s.tid = t.tid) AND"
          . $sql . "ORDER BY featured DESC, date DESC LIMIT 0, 1";
-
+         
     $msql['mssql']="SELECT STRAIGHT_JOIN s.title "
          . "FROM {$_TABLES['stories']} AS s, {$_TABLES['users']} AS u, "
          . "{$_TABLES['topics']} AS t WHERE (s.uid = u.uid) AND (s.tid = t.tid) AND"
          . $sql . "ORDER BY featured DESC, date DESC LIMIT 0, 1";
+         
+    $msql['pgsql']="SELECT s.title "
+     . "FROM {$_TABLES['stories']} AS s, {$_TABLES['users']} AS u, "
+     . "{$_TABLES['topics']} AS t WHERE (s.uid = u.uid) AND (s.tid = t.tid)"
+     . $sql . "ORDER BY featured DESC, date DESC LIMIT 1, OFFSET 0";
+         
     $result = DB_query ($msql);
 
     if ( $A = DB_fetchArray( $result ) ) {
@@ -281,6 +287,13 @@
          . "FROM {$_TABLES['stories']} AS s, {$_TABLES['users']} AS u, "
          . "{$_TABLES['topics']} AS t WHERE (s.uid = u.uid) AND (s.tid = t.tid) AND"
          . $sql . "ORDER BY featured DESC, date DESC LIMIT $offset, $limit";
+         
+$msql['pgsql']="SELECT s.*, UNIX_TIMESTAMP(s.date) AS unixdate, "
+         . 'UNIX_TIMESTAMP(s.expire) as expireunix, '
+         . $userfields . ", t.topic, t.imageurl "
+         . "FROM {$_TABLES['stories']} AS s, {$_TABLES['users']} AS u, "
+         . "{$_TABLES['topics']} AS t WHERE (s.uid = u.uid) AND (s.tid = t.tid) "
+         . $sql . "ORDER BY featured DESC, date DESC LIMIT $limit, OFFSET $offset";
 
 $result = DB_query ($msql);
 
diff -r 96929262c25b -r 1c0ea36804ac public_html/lib-common.php
--- a/public_html/lib-common.php	Thu Jun 04 19:21:29 2009 -0400
+++ b/public_html/lib-common.php	Sat Jun 13 23:12:39 2009 -0400
@@ -71,7 +71,7 @@
 * Must make sure that the function hasn't been disabled before calling it.
 *
 */
-if (function_exists('set_error_handler')) {
+if (function_exists('motherfucker_set_error_handler')) {
     if (PHP_VERSION >= 5) {
         /* Tell the error handler to use the default error reporting options.
          * You may like to change this to use it in more/less cases, if so,
@@ -385,7 +385,7 @@
 *
 */
 
-require_once $_CONF['path_language'] . $_CONF['language'] . '.php';
+require_once 'C:\wamp\www\geeklog\public_html\admin\install\language\english.php';
 
 if (empty($LANG_DIRECTION)) {
     // default to left-to-right
@@ -3441,6 +3441,8 @@
     $blocksql['mssql'] .= "group_id, perm_owner, perm_group, perm_members, perm_anon, allow_autotags,UNIX_TIMESTAMP(rdfupdated) AS date ";
 
     $blocksql['mysql'] = "SELECT *,UNIX_TIMESTAMP(rdfupdated) AS date ";
+    $blocksql['pgsql'] = 'SELECT *, date_part(\'epoch\', rdfupdated) AS date ';
+
 
     $commonsql = "FROM {$_TABLES['blocks']} WHERE is_enabled = 1";
 
@@ -3455,8 +3457,7 @@
 
     if( !empty( $topic ))
     {
-        $tp = addslashes($topic);
-        $commonsql .= " AND (tid = '$tp' OR tid = 'all')";
+        $commonsql .= " AND (tid = '$topic' OR tid = 'all')";
     }
     else
     {
@@ -3481,6 +3482,7 @@
 
     $blocksql['mysql'] .= $commonsql;
     $blocksql['mssql'] .= $commonsql;
+    $blocksql['pgsql'] .= $commonsql;
     $result = DB_query( $blocksql );
     $nrows = DB_numRows( $result );
 
@@ -3551,12 +3553,14 @@
         $blocksql['mssql'] .= "group_id, perm_owner, perm_group, perm_members, perm_anon, allow_autotags,UNIX_TIMESTAMP(rdfupdated) AS date ";
 
         $blocksql['mysql'] = "SELECT *,UNIX_TIMESTAMP(rdfupdated) AS date ";
-
+        $blocksql['pgsql'] =  'SELECT *, date_part(\'epoch\', rdfupdated) AS date';
+        
         $commonsql = "FROM {$_TABLES['blocks']} WHERE name = '"
                    . $A['name'] . '_' . $lang . "'";
 
         $blocksql['mysql'] .= $commonsql;
         $blocksql['mssql'] .= $commonsql;
+        $blocksql['pgsql'] .= $commonsql;
         $result = DB_query( $blocksql );
 
         if (DB_numRows($result) == 1) {
@@ -4036,6 +4040,7 @@
 
         $storysql = array();
         $storysql['mysql'] = "SELECT sid,uid,date AS day,title,introtext,postmode";
+        $storysql['pgsql'] = "SELECT sid,uid,date AS day,title,introtext,postmode";
 
         $storysql['mssql'] = "SELECT sid,uid,date AS day,title,CAST(introtext AS text) AS introtext,postmode";
 
@@ -4075,6 +4080,7 @@
 
         $storysql['mysql'] .= $commonsql;
         $storysql['mssql'] .= $commonsql;
+        $storysql['pgsql'] .= $commonsql;
 
         $stories = DB_query( $storysql );
         $nsrows = DB_numRows( $stories );
@@ -4508,7 +4514,7 @@
                 $message = $$var;
             } else {
                 $message = sprintf($MESSAGE[61], $plugin);
-                COM_errorLog($message . ": " . $var, 1);
+                COM_errorLog($MESSAGE[61] . ": " . $var, 1);
             }
         } else {
             $message = $MESSAGE[$msg];
@@ -5807,28 +5813,32 @@
 */
 function COM_highlightQuery( $text, $query, $class = 'highlight' )
 {
-    // escape PCRE special characters
-    $query = preg_quote($query, '/');
-
-    $mywords = explode(' ', $query);
-    foreach ($mywords as $searchword)
-    {
-        if (!empty($searchword))
-        {
-            $before = "/(?!(?:[^<]+>|[^>]+<\/a>))\b";
-            $after = "\b/i";
-            if ($searchword <> utf8_encode($searchword)) {
-                 if (@preg_match('/^\pL$/u', urldecode('%C3%B1'))) { // Unicode property support
-                      $before = "/(?<!\p{L})";
-                      $after = "(?!\p{L})/u";
-                 } else {
-                      $before = "/";
-                      $after = "/u";
-                 }
-            }
-            $text = preg_replace($before . $searchword . $after, "<span class=\"$class\">\\0</span>", '<!-- x -->' . $text . '<!-- x -->' );
-        }
-    }
+    $query = str_replace( '+', ' ', $query );
+
+    // escape all the other PCRE special characters
+    $query = preg_quote( $query );
+
+    // ugly workaround:
+    // Using the /e modifier in preg_replace will cause all double quotes to
+    // be returned as \" - so we replace all \" in the result with unescaped
+    // double quotes. Any actual \" in the original text therefore have to be
+    // turned into \\" first ...
+    $text = str_replace( '\\"', '\\\\"', $text );
+
+    $mywords = explode( ' ', $query );
+    foreach( $mywords as $searchword )
+    {
+        if( !empty( $searchword ))
+        {
+            $searchword = preg_quote( str_replace( "'", "\'", $searchword ));
+            $searchword = str_replace('/', '\\/', $searchword);
+            $text = preg_replace( '/(\>(((?>[^><]+)|(?R))*)\<)/ie', "preg_replace('/(?>$searchword+)/i','<span class=\"$class\">\\\\0</span>','\\0')", '<!-- x -->' . $text . '<!-- x -->' );
+        }
+    }
+
+    // ugly workaround, part 2
+    $text = str_replace( '\\"', '"', $text );
+
     return $text;
 }
 
diff -r 96929262c25b -r 1c0ea36804ac system/databases/pgsql.class.php
--- a/system/databases/pgsql.class.php	Thu Jun 04 19:21:29 2009 -0400
+++ b/system/databases/pgsql.class.php	Sat Jun 13 23:12:39 2009 -0400
@@ -341,6 +341,8 @@
             $this->_errorlog("\n***inside database->dbQuery***");
             $this->_errorlog("\n*** sql to execute is $sql ***");
         }
+        /* Replace some non ANSI keywords */
+        $sql = str_replace('UNIX_TIMESTAMP()','date_part(\'epoch\',now())',$sql);
 
         // Run query
         if ($ignore_errors == 1) {
diff -r 96929262c25b -r 1c0ea36804ac system/lib-database.php
--- a/system/lib-database.php	Thu Jun 04 19:21:29 2009 -0400
+++ b/system/lib-database.php	Sat Jun 13 23:12:39 2009 -0400
@@ -562,6 +562,12 @@
             $exists = true;
         }
     }
+    elseif ($_DB_dbms == 'pgsql') {
+        $result = DB_query("SELECT 1 FROM '{$_TABLES[$table]}'");
+        if (DB_numRows ($result) > 0) {
+            $exists = true;
+        }
+    }
 
     return $exists;
 }
diff -r 96929262c25b -r 1c0ea36804ac system/lib-story.php
--- a/system/lib-story.php	Thu Jun 04 19:21:29 2009 -0400
+++ b/system/lib-story.php	Sat Jun 13 23:12:39 2009 -0400
@@ -1475,6 +1475,7 @@
         $max_items = $_CONF['atom_max_stories'] + 1;
 
         $limit = " LIMIT $offset, $max_items";
+        $limit_pgsql = " LIMIT $max_items OFFSET $offset";
         $order = " ORDER BY unixdate DESC";
 
         $sql['mysql']
@@ -1484,6 +1485,7 @@
         $sql['mssql'] =
             "SELECT STRAIGHT_JOIN s.sid, s.uid, s.draft_flag, s.tid, s.date, s.title, CAST(s.introtext AS text) AS introtext, CAST(s.bodytext AS text) AS bodytext, s.hits, s.numemails, s.comments, s.trackbacks, s.related, s.featured, s.show_topic_icon, s.commentcode, s.trackbackcode, s.statuscode, s.expire, s.postmode, s.frontpage, s.owner_id, s.group_id, s.perm_owner, s.perm_group, s.perm_members, s.perm_anon, s.advanced_editor_mode, " . " UNIX_TIMESTAMP(s.date) AS unixdate, UNIX_TIMESTAMP(s.expire) as expireunix, " . "u.username, u.fullname, u.photo, u.email, t.topic, t.imageurl " . "FROM {$_TABLES['stories']} AS s, {$_TABLES['users']} AS u, {$_TABLES['topics']} AS t " . "WHERE (s.uid = u.uid) AND (s.tid = t.tid)" . COM_getPermSQL('AND', $_USER['uid'], 2, 's') . $order . $limit;
 
+        $sql['pgsql'] = "SELECT  s.*, date_part('epoch', s.date) AS unixdate, date_part('epoch', s.expire) as expireunix, u.username, u.fullname, u.photo, u.email, t.topic, t.imageurl  FROM stories s, users u, topics t WHERE (s.uid = u.uid) AND (s.tid = t.tid) FROM {$_TABLES['stories']} AS s, {$_TABLES['users']} AS u, {$_TABLES['topics']} AS t WHERE (s.uid = u.uid) AND (s.tid = t.tid)" . COM_getPermSQL('AND', $_USER['uid'], 2, 's') . $order . $limit_pgsql;
         $result = DB_query($sql);
 
         $count = 0;



More information about the geeklog-cvs mailing list