Package base :: Package includes :: Module database
[hide private]

Module database

source code

Wrapper for database interface code.
See Also:
Drupy Homepage, Drupal Homepage
Notes:

Author: Brendon Crawford

Copyright: 2008 Brendon Crawford

Contact: message144 at users dot sourceforge dot net

Version: 0.1

Functions [hide private]
 
update_sql(sql)
Allow the use of different database servers using the same code base.
source code
 
prefix_tables(sql)
Append a database prefix to all tables in a query.
source code
 
set_active(name='default')
Activate a database for future queries.
source code
 
_error_page(error='')
Helper function to show fatal database errors.
source code
 
is_active()
Returns a boolean depending on the availability of the database.
source code
 
_query_callback(match, init=False)
Helper function for db_query().
source code
 
placeholders(arguments, type='int')
Generate placeholders for an array of query arguments of a single type.
source code
 
_rewrite_sql(query='', primary_table='n', primary_field='nid', args=[]) source code
 
rewrite_sql(query, primary_table='n', primary_field='nid', args=[]) source code
 
escape_table(string_) source code
 
db_create_table(ret, name, table) source code
 
field_names(fields) source code
 
type_placeholder(type_) source code
Variables [hide private]
  __version__ = '$Revision: 1 $'
  DB_ERROR = 'a515ac9c2796ca0e23adbe92c68fc9fc'
  DB_QUERY_REGEXP = '/(%d|%s|%%|%f|%b|%n)/'
Function Details [hide private]

update_sql(sql)

source code 
Allow the use of different database servers using the same code base. Drupal provides a slim database abstraction layer to provide developers with the ability to support multiple database servers easily. The intent of this layer is to preserve the syntax and power of SQL as much as possible, while letting Drupal control the pieces of queries that need to be written differently for different servers and provide basic security checks. Most Drupal database queries are performed by a call to db_query() or db_query_range(). Module authors should also consider using pager_query() for queries that return results that need to be presented on multiple pages, and tablesort_sql() for generating appropriate queries for sortable tables. For example, one might wish to return a list of the most recent 10 nodes authored by a given user. Instead of directly issuing the SQL query
Parameters:
  • sql - A string containing a complete SQL query. %-substitution parameters are not supported.
Returns:
An array containing the keys: success: a boolean indicating whether the query succeeded query: the SQL query executed, passed through check_plain()

prefix_tables(sql)

source code 
Append a database prefix to all tables in a query. Queries sent to Drupal should wrap all table names in curly brackets. This function searches for this syntax and adds Drupal's table prefix to all tables, allowing Drupal to coexist with other systems in the same database if necessary.
Parameters:
  • sql - A string containing a partial or entire SQL query.
Returns:
The properly-prefixed string.

set_active(name='default')

source code 
Activate a database for future queries. If it is necessary to use external databases in a project, this function can be used to change where database queries are sent. If the database has not yet been used, it is initialized using the URL specified for that name in Drupal's configuration file. If this name is not defined, a duplicate of the default connection is made instead. Be sure to change the connection back to the default when done with custom code.
Parameters:
  • name - The name assigned to the newly active database connection. If omitted, the default connection will be made active.
Returns:
the name of the previously active database or FALSE if non was found.

To Do: BC: Need to eventually resolve the database importing mechanism here right now we are statically loading mysql at the top, but eventually we need to get this figured out

_error_page(error='')

source code 
Helper function to show fatal database errors. Prints a themed maintenance page with the 'Site off-line' text, adding the provided error message in the case of 'display_errors' set to on. Ends the page request; no return.
Parameters:
  • error - The error message to be appended if 'display_errors' is on.

placeholders(arguments, type='int')

source code 
Generate placeholders for an array of query arguments of a single type. Given a Schema API field type, return correct %-placeholders to embed in a query
Parameters:
  • arguments - An array with at least one element.
  • type - The Schema API type of a field (e.g. 'int', 'text', or 'varchar').