CRM_Core_DAO::executeQuery('SET @uniqueID = %1', array(1 => array(CRM_Utils_Request::id(), 'String')));
}
+ /**
+ * @return DB_common
+ */
+ public static function getConnection() {
+ global $_DB_DATAOBJECT;
+ $dao = new CRM_Core_DAO();
+ return $_DB_DATAOBJECT['CONNECTIONS'][$dao->_database_dsn_md5];
+ }
+
/**
* @param string $fieldName
* @param $fieldDef
}
/**
- * @param $dsn
+ * @param string|NULL $dsn
+ * Use NULL to load the default/active connection from CRM_Core_DAO.
+ * Otherwise, give a full DSN string.
* @param string $fileName
* @param null $prefix
* @param bool $isQueryString
* @param bool $dieOnErrors
*/
public static function sourceSQLFile($dsn, $fileName, $prefix = NULL, $isQueryString = FALSE, $dieOnErrors = TRUE) {
- require_once 'DB.php';
+ if ($dsn === NULL) {
+ $db = CRM_Core_DAO::getConnection();
+ }
+ else {
+ require_once 'DB.php';
+ $db = DB::connect($dsn);
+ }
- $db = DB::connect($dsn);
if (PEAR::isError($db)) {
die("Cannot open $dsn: " . $db->getMessage());
}
* Load saved search sql files into the DB.
*/
public function loadSavedSearches() {
- $dsn = CRM_Core_Config::singleton()->dsn;
foreach (glob(dirname(__FILE__) . "/SavedSearchDataSets/*.sql") as $file) {
- CRM_Utils_File::sourceSQLFile($dsn, $file);
+ CRM_Utils_File::sourceSQLFile(NULL, $file);
}
}