| 1 |
<?php
|
| 2 |
// $Id: database-common.inc,v 1.1.2.3 2009/02/04 01:59:00 daften Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Wrapper for database interface code.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Activate a database for bugbits queries. Don't forget to call _bugbits_db_set_inactive() to reactivate to
|
| 11 |
* default drupal database
|
| 12 |
*
|
| 13 |
* @return the name of the previously active database or FALSE if non was found.
|
| 14 |
*/
|
| 15 |
function _bugbits_db_set_active() {
|
| 16 |
global $bugbits_drupal_db_name;
|
| 17 |
|
| 18 |
$bugbits_drupal_db_name = db_set_active();
|
| 19 |
|
| 20 |
$bugbits_db_type = variable_get('bugbits_db_type', '');
|
| 21 |
$bugbits_db_handler = drupal_get_path('module', 'bugbits') . "/database.$bugbits_db_type.inc";
|
| 22 |
|
| 23 |
if (is_file($bugbits_db_handler)) {
|
| 24 |
include_once $bugbits_db_handler;
|
| 25 |
}
|
| 26 |
else {
|
| 27 |
watchdog("Bugbits", "Bugbits setup is not done properly, database type unknown", array(), WATCHDOG_ERROR);
|
| 28 |
}
|
| 29 |
}
|
| 30 |
|
| 31 |
/**
|
| 32 |
* Activate the drupal database that was used before the bugbits hook took over.
|
| 33 |
*
|
| 34 |
* @return the name of the previously active database or FALSE if non was found.
|
| 35 |
*/
|
| 36 |
function _bugbits_db_set_inactive() {
|
| 37 |
global $bugbits_drupal_db_name;
|
| 38 |
|
| 39 |
db_set_active($bugbits_drupal_db_name);
|
| 40 |
}
|
| 41 |
|
| 42 |
/**
|
| 43 |
* Append a database prefix to all tables in a query.
|
| 44 |
*
|
| 45 |
* Queries sent to Drupal should wrap all table names in curly brackets. This
|
| 46 |
* function searches for this syntax and adds Drupal's table prefix to all
|
| 47 |
* tables, allowing Drupal to coexist with other systems in the same database if
|
| 48 |
* necessary.
|
| 49 |
*
|
| 50 |
* @param $sql
|
| 51 |
* A string containing a partial or entire SQL query.
|
| 52 |
* @return
|
| 53 |
* The properly-prefixed string.
|
| 54 |
*/
|
| 55 |
function _bugbits_db_prefix_tables($sql) {
|
| 56 |
$db_prefix = variable_get('bugbits_table_prefix', '');
|
| 57 |
return strtr($sql, array('{' => $db_prefix, '}' => ''));
|
| 58 |
}
|