Changeset 441
- Timestamp:
- 11/17/07 08:12:30 (1 year ago)
- Files:
-
- branches/kaste/framework/lib/AkActiveRecord.php (modified) (3 diffs)
- branches/kaste/framework/lib/AkActiveRecord/AkDbAdapter.php (modified) (4 diffs)
- branches/kaste/framework/lib/AkActiveRecord/AkDbAdapter_mysql.php (modified) (2 diffs)
- branches/kaste/framework/lib/AkInstaller.php (modified) (1 diff)
- branches/kaste/framework/lib/AkUnitTest.php (modified) (1 diff)
- branches/kaste/framework/test/unit/lib/AkActiveRecord/AkDbAdapter_schema.php (modified) (3 diffs)
- branches/kaste/framework/test/unit/lib/AkInstaller.php (modified) (3 diffs)
- branches/kaste/framework/test/unit/lib/utils/_Ak_object_inspection.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/kaste/framework/lib/AkActiveRecord.php
r437 r441 2052 2052 function hasAttribute ($attribute) 2053 2053 { 2054 empty($this->_columns) ? $this->getColumns() : $this->_columns; 2054 empty($this->_columns) ? $this->getColumns() : $this->_columns; // HINT: only used by HasAndBelongsToMany joinObjects, if the table is not present yet! 2055 2055 return isset($this->_columns[$attribute]) || (!empty($this->_combinedAttributes) && $this->isCombinedAttribute($attribute)); 2056 2056 } … … 2439 2439 if(empty($_SESSION['__activeRecordColumnsSettingsCache']['available_tables']) || 2440 2440 !AK_ACTIVE_RECORD_ENABLE_PERSISTENCE){ 2441 $_SESSION['__activeRecordColumnsSettingsCache']['available_tables'] = $this->_db-> MetaTables();2441 $_SESSION['__activeRecordColumnsSettingsCache']['available_tables'] = $this->_db->availableTables(); 2442 2442 } 2443 2443 $available_tables = $_SESSION['__activeRecordColumnsSettingsCache']['available_tables']; … … 2543 2543 { 2544 2544 if(empty($_SESSION['__activeRecordColumnsSettingsCache']['database_table_'.$table.'_internals']) || !AK_ACTIVE_RECORD_ENABLE_PERSISTENCE){ 2545 $_SESSION['__activeRecordColumnsSettingsCache']['database_table_'.$table.'_internals'] = $this->_db-> MetaColumns($table);2545 $_SESSION['__activeRecordColumnsSettingsCache']['database_table_'.$table.'_internals'] = $this->_db->getColumnDetails($table); 2546 2546 } 2547 2547 $cache[$table] = $_SESSION['__activeRecordColumnsSettingsCache']['database_table_'.$table.'_internals']; branches/kaste/framework/lib/AkActiveRecord/AkDbAdapter.php
r437 r441 40 40 function __destruct() 41 41 { 42 var_dump(self::$delegated_methods);42 //var_dump(self::$delegated_methods); 43 43 //var_dump(self::$delegated_properties); 44 44 } … … 308 308 } 309 309 310 /* TRANSACTIONS */ 311 312 function startTransaction() 313 { 314 return $this->connection->StartTrans(); 315 } 316 317 function stopTransaction() 318 { 319 return $this->connection->CompleteTrans(); 320 } 321 322 function failTransaction() 323 { 324 return $this->connection->FailTrans(); 325 } 326 327 function hasTransactionFailed() 328 { 329 return $this->connection->HasFailedTrans(); 330 } 310 331 311 332 /* SCHEMA */ … … 316 337 } 317 338 318 /* TRANSACTIONS */319 320 function startTransaction()321 {322 return $this->connection->StartTrans();323 }324 325 function stopTransaction()326 {327 return $this->connection->CompleteTrans();328 }329 330 function failTransaction()331 {332 return $this->connection->FailTrans();333 }334 335 function hasTransactionFailed()336 {337 return $this->connection->HasFailedTrans();338 }339 340 339 /* META */ 340 341 341 function availableTables() 342 342 { … … 346 346 function getColumnDetails($table_name) 347 347 { 348 349 } 348 return $this->connection->MetaColumns($table_name); 349 } 350 351 /* QUOTING */ 352 353 function __quote_string($value) 354 { 355 return $this->connection->qstr($value); 356 } 357 358 350 359 } 351 360 branches/kaste/framework/lib/AkActiveRecord/AkDbAdapter_mysql.php
r435 r441 18 18 * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html> 19 19 */ 20 21 /* nothing in here, its more a demo */22 20 23 21 class AkDbAdapter_mysql extends AkDbAdapter … … 65 63 } 66 64 $column_type_definition = $column_details['Type']; 67 if ($column_details['Null'] =='NO') $column_type_definition .= ' not null';65 if ($column_details['Null']!=='YES') $column_type_definition .= ' not null'; 68 66 if (!empty($column_details['Default'])) $column_type_definition .= " default '".$column_details['Default']."'"; 69 67 return $this->sqlexecute("ALTER TABLE $table_name CHANGE COLUMN $column_name $new_name $column_type_definition"); 70 68 } 71 69 70 function availableTables() 71 { 72 return $this->selectValues('SHOW TABLES'); 73 } 74 75 76 72 77 } 73 78 ?> branches/kaste/framework/lib/AkInstaller.php
r437 r441 371 371 { 372 372 if(empty($this->available_tables)){ 373 $this->available_tables = array_diff((array)$this->db->MetaTables(), array(''));373 $this->available_tables = $this->db->availableTables(); 374 374 } 375 375 return $this->available_tables; branches/kaste/framework/lib/AkUnitTest.php
r418 r441 96 96 return false; 97 97 } 98 $installer = new AkInstaller();98 $installer =& new AkInstaller(); 99 99 $installer->dropTable($table_name,array('sequence'=>true)); 100 100 $installer->createTable($table_name,$table_definition); branches/kaste/framework/test/unit/lib/AkActiveRecord/AkDbAdapter_schema.php
r435 r441 9 9 { 10 10 11 function test_should_rename_column_mysql() 11 function test_should_return_available_tables_for_mysql() 12 { 13 $db =& AkDbAdapter::getConnection(); 14 if ($db->type() !== 'mysql') return; 15 $old_adodb_style = $db->connection->MetaTables(); 16 $new_implementation = $db->availableTables(); 17 $this->assertEqual($old_adodb_style,$new_implementation); 18 } 19 20 function test_should_return_column_details() 21 { 22 $this->installAndIncludeModels(array( 23 'AkTestUser'=>'id,user_name string(32),email string(150), visits int default 1, taken bool, created_at, updated_at, expires_on' 24 )); 25 $db =& AkDbAdapter::getConnection(); 26 $old_adodb_style = $db->connection->MetaColumns('ak_test_users'); 27 $new_implementation = $db->getColumnDetails('ak_test_users'); 28 $this->assertEqual($old_adodb_style,$new_implementation); 29 } 30 31 function _test_column_details_should_serve_activerecord_with_a_processed_array() 32 { 33 $this->installAndIncludeModels(array( 34 'AkTestUser'=>'id,user_name string(32),email string(150), visits int default 1, taken bool, created_at, updated_at, expires_on' 35 )); 36 $db =& AkDbAdapter::getConnection(); 37 $processed_return = $db->getColumnDetails('ak_test_users'); 38 $expected_return = $this->AkTestUser->getColumns(); 39 $this->assertEqual($processed_return,$expected_return); 40 } 41 42 function test_should_rename_columns_for_mysql() 12 43 { 13 44 $db =& AkDbAdapter::getConnection(); … … 18 49 )); 19 50 $table_name = 'rename_columns'; 20 $this-> mysql_rename($db, $table_name,'namen','name');21 $this-> mysql_rename($db, $table_name,'help','nohelp');22 $this-> mysql_rename($db, $table_name,'postcunt','postcount');51 $this->_mysql_rename($db, $table_name,'namen','name'); 52 $this->_mysql_rename($db, $table_name,'help','nohelp'); 53 $this->_mysql_rename($db, $table_name,'postcunt','postcount'); 23 54 24 55 $this->assertError($db->renameColumn($table_name,'not_found','not_here')); 25 56 } 26 57 27 function mysql_rename($db, $table_name,$old_name,$new_name)58 function _mysql_rename($db, $table_name,$old_name,$new_name) 28 59 { 29 60 $old = $db->select("SHOW COLUMNS FROM $table_name LIKE '$old_name'"); … … 38 69 } 39 70 40 function test_should_rename_column _postgre()71 function test_should_rename_columns_for_postgre() 41 72 { 42 73 $db =& AkDbAdapter::getConnection(); branches/kaste/framework/test/unit/lib/AkInstaller.php
r435 r441 120 120 "); 121 121 122 $from_datadict = $this->Installer->db-> MetaColumns('test_pages');122 $from_datadict = $this->Installer->db->getColumnDetails('test_pages'); 123 123 124 124 foreach ($this->expected_for_creating_table as $column=>$details){ … … 237 237 $this->Installer = new AkInstaller(); 238 238 $this->Installer->createTable('test_defaults','id,name,screen_name string,description,*url,owner_id,modified_at,created_on,is_featured,position,lock_version'); 239 $from_datadict = $this->Installer->db-> MetaColumns('test_defaults');239 $from_datadict = $this->Installer->db->getColumnDetails('test_defaults'); 240 240 241 241 foreach ($this->expected_for_default_types as $column=>$details){ … … 274 274 { 275 275 $this->Installer->renameColumn('test_defaults','screen_name','real_name'); 276 $this->Installer->dropTable('test_defaults'); 276 277 } 277 278 branches/kaste/framework/test/unit/lib/utils/_Ak_object_inspection.php
r217 r441 59 59 require_once(AK_CONTRIB_DIR.'/adodb/adodb.inc.php'); 60 60 61 if(substr($GLOBALS['ak_test_db_dns'], 0, 6) == 'mysql:'){ 62 $GLOBALS['ak_test_db_dns'] = substr_replace($GLOBALS['ak_test_db_dns'], 'mysqlt:', 0, 6); 63 } 64 65 $db =& Ak::db($GLOBALS['ak_test_db_dns']); 61 $db =& Ak::db(); 66 62 $this->assertFalse(!$db,'Connecting to the database. Please check your test_config.php file in order to set up a copy of $dns into $GLOBALS["ak_test_db_dns"]'); 67 $this->assertReference($db,Ak::db( $GLOBALS['ak_test_db_dns']),'Checking db connection singleton');63 $this->assertReference($db,Ak::db(),'Checking db connection singleton'); 68 64 } 69 65
