summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKiraly Peter2013-07-13 11:43:45 (GMT)
committer Kiraly Peter2013-07-13 11:43:45 (GMT)
commit5cd42acf840ba08847b2972f9c5fdd0e26d1779e (patch)
tree31e18264c809ceda20f9b1d6c2699a55cc877cba
parent5200384e7ae3dd6278940d9bef4c08e003e944f6 (diff)
Refactoring xc_sql_xc_retrieve().
-rw-r--r--xc_sql/xc_sql.module25
1 files changed, 19 insertions, 6 deletions
diff --git a/xc_sql/xc_sql.module b/xc_sql/xc_sql.module
index 8446e9c..10ff652 100644
--- a/xc_sql/xc_sql.module
+++ b/xc_sql/xc_sql.module
@@ -379,6 +379,7 @@ function xc_sql_xc_remove(&$entity, $locations, $params = array()) {
* @return array Array of XCEntity objects
*/
function xc_sql_xc_retrieve(&$entity, $location = NULL, $params = array()) {
+ static $sql_metadata, $sql_metadata_with_location;
/*
if (!empty($param)) {
$definition = $params['definition'];
@@ -387,18 +388,30 @@ function xc_sql_xc_retrieve(&$entity, $location = NULL, $params = array()) {
$relationships = $params['relationships'];
}
*/
+ if ($entity === FALSE) {
+ return;
+ }
if (isset($location) && $location->has_sql_type) {
- $_object = db_query('SELECT metadata FROM {xc_sql_metadata} WHERE metadata_id = :metadata_id AND location_id = :location_id', array(':metadata_id' => $entity->metadata_id, ':location_id' => $location->location_id))->fetchObject();
- if ($entity !== FALSE) {
- $entity->metadata = unserialize($_object->metadata);
+ if (!isset($sql_metadata_with_location)) {
+ $sql_metadata_with_location = 'SELECT metadata FROM {xc_sql_metadata} WHERE metadata_id = :metadata_id AND location_id = :location_id';
}
+ $_object = db_query($sql_metadata_with_location, array(
+ ':metadata_id' => $entity->metadata_id,
+ ':location_id' => $location->location_id))
+ ->fetchObject();
}
else {
- $_object = db_query('SELECT metadata FROM {xc_sql_metadata} WHERE metadata_id = :metadata_id', array(':metadata_id' => $entity->metadata_id))->fetchObject();
- if ($entity !== FALSE) {
- $entity->metadata = unserialize($_object->metadata);
+ if (!isset($sql_metadata)) {
+ $sql_metadata = 'SELECT * FROM {xc_sql_metadata} WHERE metadata_id = :metadata_id';
}
+ $_object = db_query($sql_metadata, array(
+ ':metadata_id' => $entity->metadata_id))
+ ->fetchObject();
+ }
+
+ if ($_object !== FALSE && isset($_object->metadata)) {
+ $entity->metadata = unserialize($_object->metadata);
}
}