Changeset 249 for trunk/trax/vendor/trax
- Timestamp:
- 08/24/06 13:18:40 (6 years ago)
- Location:
- trunk/trax/vendor/trax
- Files:
-
- 2 modified
-
active_record.php (modified) (11 diffs)
-
templates/error.phtml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/trax/vendor/trax/active_record.php
r247 r249 370 370 */ 371 371 public static $use_transactions = false; # this will issue a rollback command if any sql fails 372 373 /** 374 * Keep a log of queries executed if in development env 375 */ 376 public static $query_log = array(); 372 377 373 378 /** … … 635 640 636 641 # Primary key value 637 $this_primary_key_value = $this->attribute_is_string($this_primary_key) ? 638 "'".$this->$this_primary_key."'" : 639 $this->$this_primary_key; 642 if($this->attribute_is_string($this_primary_key)) { 643 $this_primary_key_value = "'".$this->$this_primary_key."'"; 644 } elseif(is_numeric($this->$this_primary_key)) { 645 $this_primary_key_value = $this->$this_primary_key; 646 } else { 647 $this_primary_key_value = 0; 648 } 640 649 641 650 # Set up the SQL segments … … 712 721 713 722 $foreign_key_value = $this->$this_primary_key; 714 $conditions = ($other_class_object->attribute_is_string($foreign_key) ? 715 "$foreign_key = '{$foreign_key_value}'" : 716 "$foreign_key = {$foreign_key_value}") . $additional_conditions; 723 if($other_class_object->attribute_is_string($foreign_key)) { 724 $conditions = "{$foreign_key} = '{$foreign_key_value}'"; 725 } elseif(is_numeric($foreign_key_value)) { 726 $conditions = "{$foreign_key} = {$foreign_key_value}"; 727 } else { 728 $conditions = "{$foreign_key} = 0"; 729 } 730 $conditions .= $additional_conditions; 717 731 } 718 732 … … 765 779 766 780 $foreign_key_value = $this->$this_primary_key; 767 $conditions = ($other_class_object->attribute_is_string($foreign_key) ? 768 "{$foreign_key} = '{$foreign_key_value}'" : 769 "{$foreign_key} = {$foreign_key_value}") . $additional_conditions; 781 if($other_class_object->attribute_is_string($foreign_key)) { 782 $conditions = "{$foreign_key} = '{$foreign_key_value}'"; 783 } elseif(is_numeric($foreign_key_value)) { 784 $conditions = "{$foreign_key} = {$foreign_key_value}"; 785 } else { 786 $conditions = "{$foreign_key} = 0"; 787 } 788 789 $conditions .= $additional_conditions; 770 790 771 791 # Get the list of other_class_name objects … … 822 842 823 843 $other_primary_key_value = $this->$foreign_key; 824 $conditions = ($other_class_object->attribute_is_string($other_primary_key) ? 825 "{$other_primary_key} = '{$other_primary_key_value}'" : 826 "{$other_primary_key} = {$other_primary_key_value}") . $additional_conditions; 844 if($other_class_object->attribute_is_string($other_primary_key)) { 845 $conditions = "{$other_primary_key} = '{$other_primary_key_value}'"; 846 } elseif(is_numeric($other_primary_key_value)) { 847 $conditions = "{$other_primary_key} = {$other_primary_key_value}"; 848 } else { 849 $conditions = "{$other_primary_key} = 0"; 850 } 851 $conditions .= $additional_conditions; 827 852 828 853 # Get the list of other_class_name objects … … 962 987 if($this->column_attribute_exists($column) && ($conditions = $this->get_primary_key_conditions())) { 963 988 # Run the query to grab a specific columns value. 964 $sql = "SELECT $column FROM $this->table_name WHERE $conditions";989 $sql = "SELECT {$column} FROM {$this->table_name} WHERE {$conditions}"; 965 990 $this->log_query($sql); 966 991 $result = self::$db->getOne($sql); … … 2095 2120 && !(strcasecmp($value, 'NULL') == 0) 2096 2121 && $this->attribute_is_string($key)) { 2122 //&& !is_numeric($value)) { 2097 2123 $value = str_replace("\\\"","\"", $value); 2098 2124 $value = str_replace("\'","'", $value); … … 2120 2146 $inserts = array(); 2121 2147 foreach($attributes as $key => $value) { 2122 if(!in_array($key, $this->primary_keys) || ($value != "''" )) {2148 if(!in_array($key, $this->primary_keys) || ($value != "''" && isset($value))) { 2123 2149 $inserts[$key] = $value; 2124 2150 } … … 2150 2176 # run through our fields and join them with their values 2151 2177 foreach($attributes as $key => $value) { 2152 if(in_array($key, $this->primary_keys) ) {2178 if(in_array($key, $this->primary_keys) && isset($value) && $value != "''") { 2153 2179 $conditions[] = "$key = $value"; 2154 2180 } … … 2356 2382 */ 2357 2383 function add_error($error, $key = null) { 2358 if(!is_null($key)) 2384 if(!is_null($key)) { 2359 2385 $this->errors[$key] = $error; 2360 else2386 } else { 2361 2387 $this->errors[] = $error; 2388 } 2362 2389 } 2363 2390 … … 2628 2655 * Log SQL query in development mode 2629 2656 * 2630 * If running in development mode, log the query to $GLOBAL2657 * If running in development mode, log the query to self::$query_log 2631 2658 * @param string SQL to be logged 2632 2659 */ 2633 function log_query($ sql) {2634 if(TRAX_ENV == "development" && $ sql) {2635 $GLOBALS['ACTIVE_RECORD_SQL_LOG'][] = $sql;2660 function log_query($query) { 2661 if(TRAX_ENV == "development" && $query) { 2662 self::$query_log[] = $query; 2636 2663 } 2637 2664 } -
trunk/trax/vendor/trax/templates/error.phtml
r192 r249 49 49 <?php endif; ?> 50 50 51 <?php if(array_key_exists('ACTIVE_RECORD_SQL_LOG',$GLOBALS) 52 && count($GLOBALS['ACTIVE_RECORD_SQL_LOG'])): ?> 51 <?php if(count(ActiveRecord::$query_log)): ?> 53 52 <p><a href="#" onclick="expandContract('sql_trace')">Show SQL trace</a> 54 53 <pre id="sql_trace" style="display:none"> 55 54 <code style="word-wrap: break-word;"> 56 55 <?php $i = 0 ?> 57 <?php foreach(array_reverse( $GLOBALS['ACTIVE_RECORD_SQL_LOG']) as $sql): ?>58 #<?php echo $i++ ?> <?php echo trim($sql)?>56 <?php foreach(array_reverse(ActiveRecord::$query_log) as $query): ?> 57 #<?php echo $i++ ?> <?php echo $query."\n" ?> 59 58 <?php endforeach; ?> 60 59 </code>
