Changeset 122
- Timestamp:
- 06/29/09 22:09:25 (14 months ago)
- Files:
-
- 2 modified
-
library/classes/smysqlquery.class.php (modified) (4 diffs)
-
tests/library/classes/sMYSQLQueryTest.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
library/classes/smysqlquery.class.php
r111 r122 145 145 */ 146 146 public function setFrom($table) { 147 return $this->query-> from('`'.$this->escape($table).'`');147 return $this->query->setFrom('`'.$this->escape($table).'`'); 148 148 } 149 149 … … 153 153 public function from() { 154 154 $tables = func_get_args(); 155 $tables = $tables[0]; 156 return $this->query->from($tables); 155 foreach($tables as $table){ 156 $this->query->from('`'.$this->escape($table).'`'); 157 } 158 return true; 157 159 } 158 160 … … 326 328 $sql = "( \n /*begin subselect*/ \n".$queryObject->getSelect()."\n /*end subselect*/ \n)"; 327 329 } else { 328 $sql= 'SELECT ';330 $sql= 'SELECT'; 329 331 $sql .= $this->getColumnString($queryObject); 330 332 $sql .= ' FROM '.$this->getTableString($queryObject); … … 388 390 */ 389 391 public function getCount() { 390 $sql = "SELECT ";392 $sql = 'SELECT'; 391 393 $sql .= ' COUNT(*) ' . "\n"; 392 394 $sql .= ' FROM '.$this->getTableString(); -
tests/library/classes/sMYSQLQueryTest.php
r111 r122 55 55 { 56 56 $this->assertEquals( 57 true, 58 $this->object->connect() 59 ); 60 $this->assertEquals( 61 true, 62 $this->object->connect() 63 ); 64 $this->assertEquals( 57 65 $this->object->connect(), 58 true 59 ); 60 $this->assertEquals( 61 $this->object->connect(), 62 true 66 $this->object->connect() 63 67 ); 64 68 } … … 71 75 $this->object->connect(); 72 76 $this->assertEquals( 73 $this->object->disconnect(),74 true77 true, 78 $this->object->disconnect() 75 79 ); 76 80 //you can only disconnect once 77 81 //but you are disconnected 78 82 $this->assertEquals( 83 true, 84 $this->object->disconnect() 85 ); 86 $this->assertEquals( 79 87 $this->object->disconnect(), 80 true88 $this->object->disconnect() 81 89 ); 82 90 } … … 88 96 { 89 97 // Remove the following lines when you implement this test. 90 $this->markTestIncomplete( 91 'This test has not been implemented yet.' 92 ); 98 $this->assertEquals( 99 array(), 100 $this->object->queryDb("SELECT * FROM test WHERE id = 'asdf'") 101 ); 102 $this->assertEquals( 103 array( 104 array 105 ( 106 'id' => 1, 107 'value' => 'one' 108 ) 109 ) 110 , 111 $this->object->queryDb("SELECT * FROM test WHERE id = 1") 112 ); 113 $this->assertEquals( 114 array( 115 array 116 ( 117 'id' => 1, 118 'value' => 'one' 119 ), 120 array 121 ( 122 'id' => 2, 123 'value' => 'two' 124 ) 125 ) 126 , 127 $this->object->queryDb("SELECT * FROM test") 128 ); 93 129 } 94 130 … … 99 135 { 100 136 $this->assertEquals( 101 $this->object->newQuery(),102 true137 true, 138 $this->object->newQuery() 103 139 ); 104 140 } … … 113 149 $this->fail('Should throw exception'); 114 150 } catch(Exception $e) { 115 print_r($e->getMessage());116 151 $this->assertEquals( 117 strpos($e->getMessage(), 'Not implemented'),118 0152 0, 153 strpos($e->getMessage(), 'Not implemented') 119 154 ); 120 155 } … … 126 161 public function testGetNumRows() 127 162 { 128 // Remove the following lines when you implement this test. 129 $this->markTestIncomplete( 130 'This test has not been implemented yet.' 131 ); 163 $this->object->queryDb("SELECT * FROM test WHERE id = 'asdf'"); 164 $this->assertEquals( 165 0, 166 $this->object->getNumRows() 167 ); 168 $this->object->queryDb("SELECT * FROM test WHERE id = 1"); 169 $this->assertEquals( 170 1, 171 $this->object->getNumRows() 172 ); 173 $this->object->queryDb("SELECT * FROM test WHERE id IN (1, 2)"); 174 $this->assertEquals( 175 2, 176 $this->object->getNumRows() 177 ); 132 178 } 133 179 … … 137 183 public function testSetFrom() 138 184 { 139 // Remove the following lines when you implement this test. 140 $this->markTestIncomplete( 141 'This test has not been implemented yet.' 142 ); 185 186 try{ 187 $this->object->newQuery(); 188 $this->object->getSelect(); 189 $this->fail('Should throw exception'); 190 } catch(Exception $e) { 191 $this->assertEquals( 192 0, 193 strpos($e->getMessage(), 'You have to set a table before running this query') 194 ); 195 } 196 197 $this->object->newQuery(); 198 $this->object->setFrom('test'); 199 $select = $this->object->getSelect(); 200 $select = str_replace("\n", '', $select); 201 $this->assertEquals( 202 "SELECT * FROM `test`", 203 $select 204 ); 205 206 $this->object->setFrom('not_test'); 207 $select = $this->object->getSelect(); 208 $select = str_replace("\n", '', $select); 209 $this->assertEquals( 210 "SELECT * FROM `not_test`\n", 211 $this->object->getSelect() 212 ); 143 213 } 144 214 … … 148 218 public function testFrom() 149 219 { 150 // Remove the following lines when you implement this test. 151 $this->markTestIncomplete( 152 'This test has not been implemented yet.' 153 ); 220 $this->object->newQuery(); 221 $this->object->setFrom('test'); 222 $select = $this->object->getSelect(); 223 $select = str_replace("\n", '', $select); 224 $this->assertEquals( 225 "SELECT * FROM `test`", 226 $select 227 ); 228 229 $this->object->newQuery(); 230 $this->object->from('test'); 231 $select = $this->object->getSelect(); 232 $select = str_replace("\n", '', $select); 233 $this->assertEquals( 234 "SELECT * FROM `test`", 235 $select 236 ); 237 238 $this->object->newQuery(); 239 $this->object->from('test', 'not_test'); 240 $select = $this->object->getSelect(); 241 $select = str_replace("\n", '', $select); 242 $this->assertEquals( 243 "SELECT * FROM `test`, `not_test`", 244 $select 245 ); 246 247 $this->object->newQuery(); 248 $this->object->from('test'); 249 $this->object->from('not_test'); 250 $select = $this->object->getSelect(); 251 $select = str_replace("\n", '', $select); 252 $this->assertEquals( 253 "SELECT * FROM `test`, `not_test`", 254 $select 255 ); 256 154 257 } 155 258
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)