18 require_once SQ_INCLUDE_PATH.
'/asset.inc';
19 require_once SQ_CORE_PACKAGE_PATH.
'/data_source/data_source/data_source.inc';
20 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
21 require_once SQ_CORE_PACKAGE_PATH.
'/files/image/image.inc';
46 parent::__construct($assetid);
67 $allowed_link[
'asset'][
'card'] =
'M';
68 $allowed_link[
'asset'][
'exclusive'] = FALSE;
70 $links[SQ_LINK_TYPE_1] = $allowed_link;
71 $links[SQ_LINK_TYPE_2] = $allowed_link;
72 $links[SQ_LINK_TYPE_3] = $allowed_link;
73 $links[SQ_LINK_NOTICE] = $allowed_link;
88 $fields = $this->
attr(
'fields');
90 $fields = explode(
', ', $fields);
93 $tables = explode(
', ', $this->
attr(
'tables'));
96 foreach ($tables as $table) {
98 $sql =
'select * from '.$table;
101 if (!empty($result)) {
102 $record = $result(0);
103 foreach ($record as $key => $value) {
109 trigger_localised_error(
'DATA0001', E_USER_WARNING, $e->getMessage(), $sql);
128 $GLOBALS[
'SQ_SYSTEM']->pm->startTimer($this);
130 if (!empty($query_string)) {
131 $hash = md5($query_string);
134 if (!isset($this->_tmp[$hash])) {
138 if ($result !== FALSE) {
139 $this->_tmp[$hash] = $result;
146 $GLOBALS[
'SQ_SYSTEM']->pm->stopTimer($this);
147 return $this->_tmp[$hash];
150 $GLOBALS[
'SQ_SYSTEM']->pm->stopTimer($this);
168 $sql = $this->
attr(
'sql');
170 $keyword_wrapper =
'%%';
171 $keyword_pattern =
'('.$keyword_wrapper.
'([a-zA-Z_\-0-9\.]+)'.$keyword_wrapper.
')';
174 preg_match_all (
'/'.$keyword_pattern.
'/', $sql, $matches, PREG_PATTERN_ORDER);
175 if (empty($matches[1])) {
179 $raw_keywords =& $matches[1];
180 $keywords =& $matches[2];
183 if ($db === FALSE)
return $sql;
185 foreach ($keywords as $keyword) {
188 $replacements[] = str_replace(
'$',
'\$', $value);
189 $patterns[] =
'/('.$keyword_wrapper.$keyword.$keyword_wrapper.
')/';
192 $sql = preg_replace($patterns, $replacements, $sql);
210 if ($db === FALSE)
return Array();
211 $sql = trim($sql,
'; ');
214 $empty_result = TRUE;
215 if (
MatrixDAL::getDbType() ===
'oci' && preg_match(
'/^\s*(:?delete )|(:?insert )|(:?update )/msi', $sql)) {
223 foreach($result as $row) {
225 $empty_result = FALSE;
231 }
catch (Exception $e) {
232 trigger_localised_error(
'DATA0001', E_USER_WARNING, $e->getMessage(), $sql);
237 return $empty_result ? Array() : $result;
250 if (isset($this->_tmp[
'db_connection'])) {
251 return $this->_tmp[
'db_connection'];
255 if (empty($dsn))
return FALSE;
258 $dsn_lower = strtolower($dsn[
'DSN']);
259 if (substr($dsn_lower, 0, 4) ==
'oci:') {
260 $dsn[
'DSN'] = substr($dsn[
'DSN'], 4);
261 $dsn[
'type'] =
'oci';
265 $dsn_lower = strtolower($dsn[
'DSN']);
266 if (substr($dsn_lower, 0, 7) ==
'dbname=') {
267 $dsn[
'DSN'] = substr($dsn[
'DSN'], 7);
273 }
catch (Exception $e) {
274 $this->_tmp[
'db_conection_exception'] = $e;
279 return $this->_tmp[
'db_connection'];
292 if (isset($this->_tmp[
'db_DSN'])) {
293 return $this->_tmp[
'db_DSN'];
299 if (!empty($connector_asset)) {
300 $dsn = $connector_asset->getDSN();
307 $this->_tmp[
'db_DSN'] = $dsn;
324 $dsn = $asset->attr(
'dsn');
325 $user = $asset->attr(
'user');
326 $password = $asset->attr(
'password');
327 $type = $asset->attr(
'db_type');
345 $dsn_lower = strtolower($dsn);
346 if (substr($dsn_lower, 0, 4) ==
'oci:') {
347 $dsn = substr($dsn, 4);
351 $dsn_lower = strtolower($dsn);
352 if (substr($dsn_lower, 0, 7) ==
'dbname=') {
353 $dsn = substr($dsn, 7);
357 return Array(
'DSN' => $dsn,
'user' => $user,
'password' => $password,
'type' => $type);
370 $connector_asset = NULL;
372 $connector_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_NOTICE,
'db_connector', FALSE,
'db_connector');
373 if (empty($connector_link)) {
374 $connector_asset_id = NULL;
376 $connector_asset_id = $connector_link[
'minorid'];
379 if (!empty($connector_asset_id)) {
380 $connector_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($connector_asset_id);
383 return $connector_asset;