Changeset 11
- Timestamp:
- 07/17/08 21:10:08 (4 months ago)
- Files:
-
- trunk/shop/admin/index.php (modified) (1 diff)
- trunk/shop/admin/protected/application.xml (modified) (2 diffs)
- trunk/shop/common/CDatabase.php (added)
- trunk/shop/common/CDatabaseBase.php (modified) (16 diffs)
- trunk/shop/common/CUser.php (added)
- trunk/shop/common/CUserManager.php (added)
- trunk/shop/schema (added)
- trunk/shop/schema/postgresql (added)
- trunk/shop/schema/postgresql/core.sql (added)
- trunk/shop/tests/UnitTests/UserManager (added)
- trunk/shop/tests/UnitTests/UserManager/CUserManagerTest.php (added)
- trunk/shop/tests/UnitTests/application.xml (modified) (3 diffs)
- trunk/shop/tests/UnitTests/index.php (modified) (1 diff)
- trunk/shop/tests/test_tools/unit_tests.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/shop/admin/index.php
r3 r11 18 18 require_once('../common/CDatabaseBase.php'); 19 19 require_once('../common/Helper.php'); 20 require_once('../common/CUserManager.php'); 21 require_once('../common/CUser.php'); 20 22 21 23 $application=new TApplication; trunk/shop/admin/protected/application.xml
r3 r11 8 8 </paths> 9 9 <modules> 10 <module id="datasource" class="System.Data.TDataSourceConfig"> 11 <database ConnectionString="pgsql:host=localhost;dbname=bvjobs" 12 username="postgres" password="postgres" /> 10 <module id="database" class="CDatabase" 11 ServerType="PostgreSQL" 12 Host="localhost" 13 Database="test" 14 Username="postgres" 15 Password="postgres"/> 13 16 </module> 14 17 </modules> … … 16 19 <service id="page" class="TPageService" BasePath="Application" DefaultPage="Pages.Home"> 17 20 <modules> 18 <module id="data" class="Application.Engine.CDatabase"/>19 21 <!-- 20 22 <module id="users" class="Application.Engine.CUserManager" /> trunk/shop/common/CDatabaseBase.php
r4 r11 15 15 * 16 16 */ 17 class CDatabaseBase extends TModule17 class CDatabaseBase extends TModule 18 18 { 19 19 private $connection; … … 23 23 private $password; 24 24 private $database; 25 26 /** 27 * @return string database name 28 */ 25 private $debug_sql; 26 27 28 public function GetDebugSQL() 29 { 30 return $this->debug_sql; 31 } 32 29 33 public function getDatabase() 30 34 { … … 32 36 } 33 37 34 /**35 * @param string value database name36 */37 38 public function setDatabase($value) 38 39 { 39 40 $this->database = $value; 40 41 } 41 42 43 /** 44 * @return string password value 45 */ 42 46 43 public function getPassword() 47 44 { … … 49 46 } 50 47 51 /**52 * @param object password value53 */54 48 public function setPassword($value) 55 49 { … … 57 51 } 58 52 59 /**60 * @return string username value61 */62 53 public function getUsername() 63 54 { … … 65 56 } 66 57 67 /**68 * @param string username value69 */70 58 public function setUsername($value) 71 59 { … … 73 61 } 74 62 75 /**76 * @return string host value77 */78 63 public function getHost() 79 64 { … … 81 66 } 82 67 83 /**84 * @param string host value85 */86 68 public function setHost($value) 87 69 { … … 89 71 } 90 72 91 /**92 * @return string server type value93 */94 73 public function getServerType() 95 74 { … … 97 76 } 98 77 99 /**100 * Allowed server types are "PostgreSQL" and "MySQL"101 * @param string server type value102 */103 78 public function setServerType($value) 104 79 { … … 116 91 } 117 92 118 /**119 * Creates a database connection based on ServerType120 */121 93 private function create_connection() 122 94 { … … 140 112 } 141 113 142 /**143 * Performs a SQL query with paramsters144 * @param string sql145 * @param array params146 * @return array array[row][column] containing only the first row of the query data147 */148 114 public function queryRow($sql,$params=null) 149 115 { … … 161 127 } 162 128 163 /**164 * Performs a SQL query with paramsters165 * @param string sql166 * @param array params167 * @return array array[row][column] containing the query data168 */169 129 public function queryAll($sql,$params=null) 170 130 { … … 180 140 } 181 141 182 /**183 * Performs a SQL query with paramsters184 * @param string sql185 * @param array params186 * @return mixed single value from the first column of the first row187 */188 142 public function queryScalar($sql,$params=null) 189 143 { … … 200 154 } 201 155 202 /**203 * Performs a SQL query with paramsters204 * <code>205 * $result = query("SELECT * FROM table1 WHERE field1 = $1 AND field2 = $2",array(100,'value1'));206 * </code>207 * @param string sql208 * @param array params209 * @return resource database query result resource, not an array!210 */211 156 public function query($sql,$params=null) 212 157 { 213 if($this->server_type == "postgresql") 214 { 158 $this->debug_sql = $sql; 159 if($this->server_type == "postgresql") 160 { 215 161 if($params != null) 216 162 { … … 219 165 $params[$k] = ($v === true ? 't':'f'); 220 166 return pg_query_params($this->connection,$sql,$params); 221 }167 } 222 168 else 223 169 { 224 170 return pg_query($this->connection,$sql); 225 }171 } 226 172 } 227 173 else if($this->server_type == "mysql") trunk/shop/tests/UnitTests/application.xml
r3 r11 3 3 <application id="UnitTests" mode="Debug"> 4 4 <modules> 5 <module id="datasource" class="System.Data.TDataSourceConfig">6 <database/>7 </module>8 5 <module id="postgres" class="CDatabase" 9 6 ServerType="PostgreSQL" … … 14 11 /> 15 12 16 13 <module id="database" class="CDatabase" 14 ServerType="PostgreSQL" 15 Host="localhost" 16 Database="test" 17 Username="postgres" 18 Password="postgres" 19 /> 20 17 21 <module id="mysql" class="CDatabase" 18 22 ServerType="MySQL" … … 23 27 /> 24 28 29 <module id="users" class="CUserManager" /> 30 <module id="auth" class="System.Security.TAuthManager" UserManager="users" LoginPage="Engine.Login" /> 25 31 26 32 </modules> trunk/shop/tests/UnitTests/index.php
r3 r11 4 4 require_once('../../common/Helper.php'); 5 5 require_once('../../common/CDatabaseBase.php'); 6 require_once('../../admin/protected/Engine/CDatabase.php'); 6 require_once('../../common/CDatabase.php'); 7 require_once('../../common/CUserManager.php'); 8 require_once('../../common/CUser.php'); 9 7 10 8 11 $test_cases = dirname(__FILE__)."/"; trunk/shop/tests/test_tools/unit_tests.php
r3 r11 13 13 14 14 require_once(PRADO_FRAMEWORK.'/prado.php'); 15 16 $global_db_core_exists = false; 15 17 16 18 class TestFolder
