PageRenderTime 24ms CodeModel.GetById 15ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 1ms

/framework/core/db/functions.php

http://zoop.googlecode.com/
PHP | 264 lines | 97 code | 23 blank | 144 comment | 0 complexity | f44cc1df57dfefa8997b6f83d0caa573 MD5 | raw file
  1<?php
  2/**
  3 * Turn on echoing of sql statements
  4 *
  5 * @return nothing
  6 */
  7function SqlEchoOn()
  8{
  9	return DbModule::getDefaultConnection()->echoOn();
 10}
 11
 12/**
 13 * Turn off echoing of sql statements
 14 *
 15 */
 16function SqlEchoOff()
 17{
 18	return DbModule::getDefaultConnection()->echoOff();
 19}
 20
 21/**
 22 * Begin a transaction (not all database engines support transactions)
 23 *
 24 */
 25function SqlBeginTransaction()
 26{
 27	return DbModule::getDefaultConnection()->beginTransaction();
 28}
 29
 30/**
 31 * Commit a transaction (not all database engines support transactions)
 32 *
 33 */
 34function SqlCommitTransaction()
 35{
 36	return DbModule::getDefaultConnection()->commitTransaction();
 37}
 38
 39/**
 40 * Executes a database query.  $params must be a $key => $value array of values to substitute into $sql
 41 *
 42 * @param string $sql SQL query with parameters in the format ":variablename" or ":variablename:datatype"
 43 * @param array($key=>$value) $params ($key => value) array of parameters to substitute into the SQL query. If you are not passing parameters in, params should be an empty array()
 44 * @return DbResultSet DbResultSet object
 45 */
 46function SqlQuery($sql, $params)
 47{
 48	return DbModule::getDefaultConnection()->query($sql, $params);
 49}
 50
 51/**
 52 * Returns a DbSchema object
 53 * This function returns a DbSchema object that can be used to query the structure of the database in a DOM like fashion.
 54 *
 55 * @return DbSchema
 56 */
 57function SqlGetSchema()
 58{
 59	return DbModule::getDefaultConnection()->getSchema();
 60}
 61
 62/**
 63 * Executes a SQL statement to alter the schema
 64 * Unlike SqlQuery, this doesn't return a DbResultSet or accept parameters
 65 *
 66 * @param string $sql SQL query to execute
 67 * @returns nothing
 68 */
 69function SqlAlterSchema($sql)
 70{
 71	return DbModule::getDefaultConnection()->alterSchema($sql);
 72}
 73
 74/**
 75 * Executes the given query and returns the value of the first cell in the first row of the resultset.
 76 *
 77 * An error will occur if the query returns more than one row.
 78 *
 79 * @param string $sql SQL query with parameters in the format ":variablename" or ":variablename:datatype"
 80 * @param array($key=>$value) $params ($key => value) array of parameters to substitute into the SQL query. If you are not passing parameters in, params should be an empty array()
 81 * @return mixed value of cell or false if no record returned
 82 */
 83function SqlFetchCell($sql, $params)
 84{
 85	return DbModule::getDefaultConnection()->fetchCell($sql, $params);
 86}
 87
 88/**
 89 * Executes the given query and returns the first row of the resultset.
 90 *
 91 * An error will occur if the query returns more than one row.
 92 *
 93 * @param string $sql SQL query with parameters in the format ":variablename" or ":variablename:datatype"
 94 * @param array($key=>$value) $params ($key => value) array of parameters to substitute into the SQL query. If you are not passing parameters in, params should be an empty array()
 95 * @return array row data or false if no record returned
 96 */
 97function SqlFetchRow($sql, $params)
 98{
 99	return DbModule::getDefaultConnection()->fetchRow($sql, $params);
100}
101
102/**
103 * Returns an array containing the values from the first column of each row returned by the passed-in query
104 *
105 * @param string $sql SQL query with parameters in the format ":variablename" or ":variablename:datatype"
106 * @param array($key=>$value) $params ($key => value) array of parameters to substitute into the SQL query. If you are not passing parameters in, params should be an empty array()
107 * @return unknown
108 */
109function SqlFetchColumn($sql, $params)
110{
111	return DbModule::getDefaultConnection()->fetchColumn($sql, $params);
112}
113
114/**
115 * Returns an array of all rows returned from the given SQL statement
116 *
117 * @param string $sql SQL query with parameters in the format ":variablename" or ":variablename:datatype"
118 * @param array($key=>$value) $params ($key => value) array of parameters to substitute into the SQL query. If you are not passing parameters in, params should be an empty array()
119 * @return unknown
120 */
121function SqlFetchRows($sql, $params)
122{
123	return DbModule::getDefaultConnection()->fetchRows($sql, $params);
124}
125
126/**
127 * Returns a nested array, grouped by the fields (or field) listed in $mapFields
128 * For example, if mapFields = array("person_id", "book_id"), and the resultset returns
129 * a list of all the chapters of all the books of all the people, this will group the
130 * records by person and by book, keeping each row in an array under
131 * $var[$person_id][$book_id]
132 *
133 * @param string $sql SQL query with parameters in the format ":variablename" or ":variablename:datatype"
134 * @param array $mapFields array of fields to group the results by
135 * @param array($key=>$value) $params ($key => value) array of parameters to substitute into the SQL query. If you are not passing parameters in, params should be an empty array()
136 * @return associative array structure grouped by the values in $mapFields
137 */
138function SqlFetchMap($sql, $mapFields, $params)
139{
140	return DbModule::getDefaultConnection()->fetchMap($sql, $mapFields, $params);
141}
142
143/**
144 * Creates a simple nested array structure grouping the values of the $valueField column by the values of the columns specified in the $keyFields array.
145 *
146 * For example, if your query returns a list of books and you'd like to group the titles by subject and isbn number, let $keyFields = array("subject", "isbn") and $valueField = "title".
147 * The format thus created will be $var[$subject][$isbn] = $title;
148 *
149 * @param string $sql SQL query with parameters in the format ":variablename" or ":variablename:datatype"
150 * @param array $keyFields array of fields to group the results by
151 * @param array $valueField name of the field containing the value to be grouped
152 * @param array($key=>$value) $params ($key => value) array of parameters to substitute into the SQL query. If you are not passing parameters in, params should be an empty array()
153 * @return associative array structure grouped by the values in $mapFields
154 */
155function SqlFetchSimpleMap($sql, $keyFields, $valueField, $params)
156{
157	return DbModule::getDefaultConnection()->fetchSimpleMap($sql, $keyFields, $valueField, $params);
158}
159
160/**
161 * Enter description here...
162 *
163 * @param string $tableName Table into which we will insert the data
164 * @param array $values ($key => $value) array in the format ($fieldName => $fieldValue)
165 * @param boolean $serial True if the last inserted ID should be returned
166 * @return mixed ID of the inserted row or false if $serial == false
167 */
168function SqlInsertArray($tableName, $values, $serial = true)
169{
170	return DbModule::getDefaultConnection()->insertArray($tableName, $values, $serial);
171}
172
173/**
174 * Executes an update statement on the database (identical to SqlUpdateRow)
175 *
176 * Unlike SqlQuery, this method does not return a DbResultSet objects
177 *
178 * @param string $sql SQL query with parameters in the format ":variablename" or ":variablename:datatype"
179 * @param array($key=>$value) $params ($key => value) array of parameters to substitute into the SQL query. If you are not passing parameters in, params should be an empty array()
180 * @return number Number of affected rows (not all database engines support this)
181 */
182function SqlModifyRow($sql, $params)
183{
184	// Is this supposed to work different from SqlUpdateRow?
185	//return DbModule::getDefaultConnection()->modifyRow($sql, $params);
186	return SqlUpdateRow($sql, $params);
187}
188
189/**
190 * This function is not yet implimented
191 *
192 * @param string $sql SQL query with parameters in the format ":variablename" or ":variablename:datatype"
193 * @param array($key=>$value) $params ($key => value) array of parameters to substitute into the SQL query. If you are not passing parameters in, params should be an empty array()
194 * @return unknown
195 */
196function SqlModifyRowValues($tableName, $values)
197{
198	return DbModule::getDefaultConnection()->modifyRowValues($tableName, $values);
199}
200
201/**
202 * Execute an insert statement
203 *
204 * Unlike SqlQuery, this method does not return a DbResultSet
205 *
206 * @param string $sql SQL query with parameters in the format ":variablename" or ":variablename:datatype"
207 * @param array($key=>$value) $params ($key => value) array of parameters to substitute into the SQL query. If you are not passing parameters in, params should be an empty array()
208 * @return number Number of affected rows (not all database engines support this)
209 */
210function SqlInsertRow($sql, $params)
211{
212	return DbModule::getDefaultConnection()->insertRow($sql, $params);
213}
214
215function SqlInsertRows($sql, $params)
216{
217	return DbModule::getDefaultConnection()->insertRows($sql, $params);
218}
219
220/**
221 * This function has not yet been implemented
222 *
223 * @param string $sql SQL query with parameters in the format ":variablename" or ":variablename:datatype"
224 * @param array($key=>$value) $params ($key => value) array of parameters to substitute into the SQL query. If you are not passing parameters in, params should be an empty array()
225 * @return unknown
226 */
227function SqlInsertRowValues($tableName, $values)
228{
229	return DbModule::getDefaultConnection()->insertRowValues($tableName, $values);
230}
231
232/**
233 * Executes an update statement on the database
234 *
235 * Unlike the method query(), this method does not return a DbResultSet objects
236 *
237 * @param string $sql SQL query with parameters in the format ":variablename" or ":variablename:datatype"
238 * @param array($key=>$value) $params ($key => value) array of parameters to substitute into the SQL query. If you are not passing parameters in, params should be an empty array()
239 * @return unknown
240 */
241function SqlUpdateRow($sql, $params)
242{
243	return DbModule::getDefaultConnection()->updateRow($sql, $params);
244}
245
246function SqlUpdateRows($sql, $params)
247{
248	return DbModule::getDefaultConnection()->updateRows($sql, $params);
249}
250
251function SqlSelsertRow($tableName, $fieldNames, $conditions, $defaults = NULL, $lock = 0)
252{
253	return DbModule::getDefaultConnection()->selsertRow($tableName, $fieldNames, $conditions, $defaults, $lock);
254}
255
256function SqlUpsertRow($tableName, $conditions, $values)
257{
258	return DbModule::getDefaultConnection()->upsertRow($tableName, $conditions, $values);
259}
260
261function SqlDeleteRows($sql, $params)
262{
263	return DbModule::getDefaultConnection()->deleteRows($sql, $params);
264}