/[cvs]/nfo/php/libs/com.newsblob.phphtmllib/widgets/data_list/PEARSQLDataListSource.inc
ViewVC logotype

Diff of /nfo/php/libs/com.newsblob.phphtmllib/widgets/data_list/PEARSQLDataListSource.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by jonen, Thu Jan 30 03:29:46 2003 UTC revision 1.4 by jonen, Thu May 6 16:27:50 2004 UTC
# Line 34  require_once("DB.php"); Line 34  require_once("DB.php");
34   * in to the constructor.  PEARSQLDataListSource   * in to the constructor.  PEARSQLDataListSource
35   * takes care of the rest.   * takes care of the rest.
36   *   *
37     * @author Walter A. Boring IV <waboring@buildabetterweb.com>
38     * @package phpHtmlLib
39   */   */
40  class PEARSQLDataListSource extends SQLDataListSource {  class PEARSQLDataListSource extends SQLDataListSource {
41    
# Line 70  class PEARSQLDataListSource extends SQLD Line 72  class PEARSQLDataListSource extends SQLD
72       * Set the DB object we will use       * Set the DB object we will use
73       * to talk to the DB.       * to talk to the DB.
74       *       *
75       * @param   object - $db the babw_db object.       * @param  object - $db the babw_db object.
      *  
76       */       */
77      function set_db_object( &$db ) {      function set_db_object( &$db ) {
78          $this->_db = &$db;          $this->_db = &$db;
79      }      }
80    
81        /**
82             * This is the function that does the data fetching,
83             * and sorting if needed.  
84             * If the source is a sql database, this is where the
85             * query gets called.  This function doesn't actually read the
86             * data from the DB yet.  That is what get_next_data_row()
87             * does.
88         *  
89             * @return boolean - the query passed/failed.
90             */
91          function do_query() {          function do_query() {
92                  $this->_result = $this->_db->query($this->_query);                  $this->_result = $this->_db->query($this->_query);
93                  if (DB::isError($this->_result)) {                  if (DB::isError($this->_result)) {
94                          $msg = $this->_result->getMessage();                          $msg = $this->_result->getMessage();
95                          user_error("PEARSQLDataListSource::do_query() - query failed : ".$msg);              $query = $this->_query;
96                  }                          user_error("PEARSQLDataListSource::do_query($query) - query failed : ".$msg);
97                return false;
98                    } else {
99                return true;
100            }
101          }          }
102    
103                    
# Line 114  class PEARSQLDataListSource extends SQLD Line 129  class PEARSQLDataListSource extends SQLD
129                                  $clause = " LIMIT $offset, $limit ";                                  $clause = " LIMIT $offset, $limit ";
130                                  break;                                  break;
131                          case "db_pgsql":                          case "db_pgsql":
132                                  $clause = " LIMIT $limit, $offset ";                                  $clause = " LIMIT $limit OFFSET $offset ";
133                                  break;                                  break;
134                          default:                          default:
135                                  $clause = " LIMIT $offset, $limit ";                                  $clause = " LIMIT $offset, $limit ";
# Line 137  class PEARSQLDataListSource extends SQLD Line 152  class PEARSQLDataListSource extends SQLD
152       */       */
153      function count($tables, $where_clause='', $count_clause='*') {      function count($tables, $where_clause='', $count_clause='*') {
154                  $query = "select count(".$count_clause.") as COUNT from ".$tables." ".$where_clause;                  $query = "select count(".$count_clause.") as COUNT from ".$tables." ".$where_clause;
155          $result = $this->_db->query($query);          $result = $this->_db->getOne($query);
156                  if (DB::isError($this->_result)) {                  if (DB::isError($result)) {
157                          $msg = $result->getMessage();                          $msg = $result->getMessage();
158                          user_error("PEARSQLDataListSource::count() - query failed : ".$msg);                          user_error("PEARSQLDataListSource::count() - query failed : ".$msg);
159                  }              return 0;
160                  $value = $result->fetchRow(DB_FETCHMODE_ASSOC);                  } else {
161          return ($value ? (int)$value["COUNT"] : NULL);              return $result;
162            }              
163      }      }
164            
165  }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.4

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed