diff options
Diffstat (limited to 'demos/sqlmap-sample')
24 files changed, 445 insertions, 0 deletions
diff --git a/demos/sqlmap-sample/index.php b/demos/sqlmap-sample/index.php new file mode 100644 index 00000000..43c0b436 --- /dev/null +++ b/demos/sqlmap-sample/index.php @@ -0,0 +1,18 @@ +<?php
+
+$basePath=dirname(__FILE__);
+$frameworkPath=$basePath.'/../../framework/prado.php';
+$assetsPath=$basePath.'/assets';
+$runtimePath=$basePath.'/protected/runtime';
+
+if(!is_writable($assetsPath))
+ die("Please make sure that the directory $assetsPath is writable by Web server process.");
+if(!is_writable($runtimePath))
+ die("Please make sure that the directory $runtimePath is writable by Web server process.");
+
+require_once($frameworkPath);
+
+$application=new TApplication;
+$application->run();
+
+?>
\ No newline at end of file diff --git a/demos/sqlmap-sample/protected/application.xml b/demos/sqlmap-sample/protected/application.xml new file mode 100644 index 00000000..7cfb440f --- /dev/null +++ b/demos/sqlmap-sample/protected/application.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="utf-8"?>
+<application id="Database" Mode="Debug">
+ <paths>
+ <alias id="Example" path="business-objects" />
+ </paths>
+ <modules>
+ <module id="cache" class="System.Caching.TSqliteCache" />
+ <module id="petshop-sqlmap"
+ enableConfigCache="true"
+ class="System.DataAccess.TSQLMap"
+ configFile="Application.petshop-sqlmap" />
+ <module id="person-sample"
+ class="System.DataAccess.TSQLMap"
+ configFile="Application.person-sqlmap" />
+ </modules>
+</application>
\ No newline at end of file diff --git a/demos/sqlmap-sample/protected/business-objects/Person.php b/demos/sqlmap-sample/protected/business-objects/Person.php new file mode 100644 index 00000000..ad9da4b3 --- /dev/null +++ b/demos/sqlmap-sample/protected/business-objects/Person.php @@ -0,0 +1,26 @@ +<?php
+
+class Person
+{
+ public $ID = -1;
+ public $FirstName = '';
+ public $LastName = '';
+
+ public $WeightInKilograms = 0.0;
+ public $HeightInMeters = 0.0;
+
+ private $_birthDate = '';
+
+ //setters and getter for BirthDate
+ public function getBirthDate()
+ {
+ return $this->_birthDate;
+ }
+
+ public function setBirthDate($value)
+ {
+ $this->_birthDate = $value;
+ }
+}
+
+?>
\ No newline at end of file diff --git a/demos/sqlmap-sample/protected/pages/Home.page b/demos/sqlmap-sample/protected/pages/Home.page new file mode 100644 index 00000000..6d059c7e --- /dev/null +++ b/demos/sqlmap-sample/protected/pages/Home.page @@ -0,0 +1,5 @@ +<ul>
+ <li><a href="index.php?page=crud1">Tutorial 1</a></li>
+ <li><a href="index.php?page=crud2">Tutorial 2</a></li>
+ <li><a href="index.php?page=ProductList">Product List</a></li>
+</ul>
\ No newline at end of file diff --git a/demos/sqlmap-sample/protected/pages/ProductList.page b/demos/sqlmap-sample/protected/pages/ProductList.page new file mode 100644 index 00000000..904d411d --- /dev/null +++ b/demos/sqlmap-sample/protected/pages/ProductList.page @@ -0,0 +1,9 @@ +<h1>Database Examples</h1>
+<com:TRepeater id="productList">
+ <prop:ItemTemplate>
+ <div>
+ Code: <%# $this->DataItem['productid'] %>
+ Category: <%# $this->DataItem['category'] %>
+ </div>
+ </prop:ItemTemplate>
+</com:TRepeater>
\ No newline at end of file diff --git a/demos/sqlmap-sample/protected/pages/ProductList.php b/demos/sqlmap-sample/protected/pages/ProductList.php new file mode 100644 index 00000000..a35c40ea --- /dev/null +++ b/demos/sqlmap-sample/protected/pages/ProductList.php @@ -0,0 +1,18 @@ +<?php
+
+class ProductList extends TPage
+{
+ public function onLoad($param)
+ {
+ parent::onLoad($param);
+ if(!$this->IsPostBack)
+ {
+ $sqlmap = $this->Application->Modules['petshop-sqlmap'];
+ $products = $sqlmap->queryForList('SelectAllProducts');
+ $this->productList->setDataSource($products);
+ $this->productList->dataBind();
+ }
+ }
+}
+
+?>
\ No newline at end of file diff --git a/demos/sqlmap-sample/protected/pages/crud1.page b/demos/sqlmap-sample/protected/pages/crud1.page new file mode 100644 index 00000000..ce467ffa --- /dev/null +++ b/demos/sqlmap-sample/protected/pages/crud1.page @@ -0,0 +1,19 @@ +<!doctype html public "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
+<head>
+ <title>Person</title>
+</head>
+
+<body>
+
+<com:TForm>
+ <h1>Person List</h1>
+ <com:TDataGrid id="personList">
+ <com:TBoundColumn DataField="BirthDate"
+ HeaderText="Birth Date"/>
+ </com:TDataGrid>
+</com:TForm>
+</body>
+</html>
\ No newline at end of file diff --git a/demos/sqlmap-sample/protected/pages/crud1.php b/demos/sqlmap-sample/protected/pages/crud1.php new file mode 100644 index 00000000..40733dc9 --- /dev/null +++ b/demos/sqlmap-sample/protected/pages/crud1.php @@ -0,0 +1,21 @@ +<?php
+
+Prado::using('Example.Person');
+
+class crud1 extends TPage
+{
+ private function loadData()
+ {
+ $sqlmap = $this->Application->Modules['person-sample'];
+ $this->personList->DataSource = $sqlmap->queryForList('SelectAll');
+ $this->personList->dataBind();
+ }
+
+ public function onLoad($param)
+ {
+ if(!$this->IsPostBack)
+ $this->loadData();
+ }
+}
+
+?>
\ No newline at end of file diff --git a/demos/sqlmap-sample/protected/pages/crud2.page b/demos/sqlmap-sample/protected/pages/crud2.page new file mode 100644 index 00000000..4d34e873 --- /dev/null +++ b/demos/sqlmap-sample/protected/pages/crud2.page @@ -0,0 +1,36 @@ +<!doctype html public "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
+<head>
+ <title>Person</title>
+</head>
+
+<body>
+
+<com:TForm>
+ <h1>Person List</h1>
+ <com:TDataGrid id="personList"
+ DataKeyField="ID"
+ AutoGenerateColumns="False"
+ OnEditCommand="editPerson"
+ OnUpdateCommand="updatePerson"
+ OnCancelCommand="refreshList"
+ OnDeleteCommand="deletePerson">
+ <com:TBoundColumn DataField="FirstName" HeaderText="First Name" />
+ <com:TBoundColumn DataField="LastName" HeaderText="Last Name" />
+ <com:TBoundColumn DataField="HeightInMeters" HeaderText="Height" />
+ <com:TBoundColumn DataField="WeightInKilograms" HeaderText="Weight" />
+
+ <com:TEditCommandColumn
+ HeaderText="Edit"
+ UpdateText="Save" />
+ <com:TButtonColumn
+ HeaderText="Delete"
+ Text="Delete"
+ CommandName="delete"/>
+ </com:TDataGrid>
+ <com:TButton Text="Add" OnClick="addNewPerson" />
+</com:TForm>
+</body>
+</html>
\ No newline at end of file diff --git a/demos/sqlmap-sample/protected/pages/crud2.php b/demos/sqlmap-sample/protected/pages/crud2.php new file mode 100644 index 00000000..46fe3893 --- /dev/null +++ b/demos/sqlmap-sample/protected/pages/crud2.php @@ -0,0 +1,79 @@ +<?php
+
+Prado::using('Example.Person');
+
+class crud2 extends TPage
+{
+ private function sqlmap()
+ {
+ return $this->Application->Modules['person-sample'];
+ }
+
+ private function loadData()
+ {
+ $this->personList->DataSource =
+ $this->sqlmap()->queryForList('SelectAll');
+ $this->personList->dataBind();
+ }
+
+ public function onLoad($param)
+ {
+ if(!$this->IsPostBack)
+ $this->loadData();
+ }
+
+ protected function editPerson($sender,$param)
+ {
+ $this->personList->EditItemIndex=$param->Item->ItemIndex;
+ $this->loadData();
+ }
+
+ protected function deletePerson($sender, $param)
+ {
+ $id = $this->getKey($sender, $param);
+
+ $this->sqlmap()->update("Delete", $id);
+ $this->loadData();
+ }
+
+ protected function updatePerson($sender, $param)
+ {
+ $person = new Person();
+ $person->FirstName = $this->getText($param, 0);
+ $person->LastName = $this->getText($param, 1);
+ $person->HeightInMeters = $this->getText($param, 2);
+ $person->WeightInKilograms = $this->getText($param, 3);
+ $person->ID = $this->getKey($sender, $param);
+
+ $this->sqlmap()->update("Update", $person);
+ $this->refreshList($sender, $param);
+ }
+
+ protected function addNewPerson($sender, $param)
+ {
+ $person = new Person;
+ $person->FirstName = "-- New Person --";
+ $this->sqlmap()->insert("Insert", $person);
+
+ $this->loadData();;
+ }
+
+ protected function refreshList($sender, $param)
+ {
+ $this->personList->EditItemIndex=-1;
+ $this->loadData();
+ }
+
+ private function getText($param, $index)
+ {
+ $item = $param->Item;
+ return $item->Cells[$index]->Controls[0]->Text;
+ }
+
+ private function getKey($sender, $param)
+ {
+ return $sender->DataKeys[$param->Item->DataSourceIndex];
+ }
+}
+
+?>
\ No newline at end of file diff --git a/demos/sqlmap-sample/protected/person-db/person.xml b/demos/sqlmap-sample/protected/person-db/person.xml new file mode 100644 index 00000000..4ffe44d9 --- /dev/null +++ b/demos/sqlmap-sample/protected/person-db/person.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="utf-8" ?>
+<sqlMap>
+
+ <select id="SelectAll" resultClass="Person">
+ SELECT
+ per_id as ID,
+ per_first_name as FirstName,
+ per_last_name as LastName,
+ per_birth_date as BirthDate,
+ per_weight_kg as WeightInKilograms,
+ per_height_m as HeightInMeters
+ FROM
+ person
+ </select>
+
+</sqlMap>
\ No newline at end of file diff --git a/demos/sqlmap-sample/protected/person-db/personHelper.xml b/demos/sqlmap-sample/protected/person-db/personHelper.xml new file mode 100644 index 00000000..ea2d4302 --- /dev/null +++ b/demos/sqlmap-sample/protected/person-db/personHelper.xml @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="utf-8" ?>
+
+<sqlMap Name="PersonHelper">
+
+ <select id="Select" parameterClass="int" resultClass="Person">
+ select
+ PER_ID as ID,
+ PER_FIRST_NAME as FirstName,
+ PER_LAST_NAME as LastName,
+ PER_BIRTH_DATE as BirthDate,
+ PER_WEIGHT_KG as WeightInKilograms,
+ PER_HEIGHT_M as HeightInMeters
+ from PERSON
+ WHERE
+ PER_ID = #value#
+ </select>
+
+ <insert id="Insert" parameterClass="Person">
+ insert into PERSON
+ (PER_ID, PER_FIRST_NAME, PER_LAST_NAME,
+ PER_BIRTH_DATE, PER_WEIGHT_KG, PER_HEIGHT_M)
+ values
+ (#ID#, #FirstName#, #LastName#,
+ #BirthDate#, #WeightInKilograms#, #HeightInMeters#)
+ </insert>
+
+ <update id="Update" parameterClass="Person">
+ update PERSON set
+ PER_FIRST_NAME = #FirstName#,
+ PER_LAST_NAME = #LastName#,
+ PER_BIRTH_DATE = #BirthDate#,
+ PER_WEIGHT_KG = #WeightInKilograms#,
+ PER_HEIGHT_M = #HeightInMeters#
+ where PER_ID = #ID#
+ </update>
+
+ <delete id="Delete" parameterClass="int">
+ delete from PERSON
+ where PER_ID = #value#
+ </delete>
+
+</sqlMap>
diff --git a/demos/sqlmap-sample/protected/person-db/test.db b/demos/sqlmap-sample/protected/person-db/test.db Binary files differnew file mode 100644 index 00000000..a40c91fe --- /dev/null +++ b/demos/sqlmap-sample/protected/person-db/test.db diff --git a/demos/sqlmap-sample/protected/person-sqlmap.xml b/demos/sqlmap-sample/protected/person-sqlmap.xml new file mode 100644 index 00000000..8d5319e8 --- /dev/null +++ b/demos/sqlmap-sample/protected/person-sqlmap.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8" ?>
+<sqlMapConfig>
+
+ <provider class="TAdodbProvider">
+ <datasource driver="sqlite" host="protected/person-db/test.db" />
+ </provider>
+
+ <sqlMaps>
+ <sqlMap resource="person-db/person.xml"/>
+ <sqlMap resource="person-db/personHelper.xml"/>
+ </sqlMaps>
+
+</sqlMapConfig>
\ No newline at end of file diff --git a/demos/sqlmap-sample/protected/petshop-db/petshop.db b/demos/sqlmap-sample/protected/petshop-db/petshop.db Binary files differnew file mode 100644 index 00000000..9a4404df --- /dev/null +++ b/demos/sqlmap-sample/protected/petshop-db/petshop.db diff --git a/demos/sqlmap-sample/protected/petshop-db/products.xml b/demos/sqlmap-sample/protected/petshop-db/products.xml new file mode 100644 index 00000000..bf1453b2 --- /dev/null +++ b/demos/sqlmap-sample/protected/petshop-db/products.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="utf-8" ?>
+<sqlmap>
+
+ <select id="SelectAllProducts">
+ SELECT *
+ FROM
+ product
+ </select>
+
+</sqlmap>
\ No newline at end of file diff --git a/demos/sqlmap-sample/protected/petshop-sqlmap.xml b/demos/sqlmap-sample/protected/petshop-sqlmap.xml new file mode 100644 index 00000000..f77fe2b7 --- /dev/null +++ b/demos/sqlmap-sample/protected/petshop-sqlmap.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8" ?>
+<sqlMapConfig>
+
+ <provider class="TAdodbProvider">
+ <datasource driver="sqlite" host="protected/petshop-db/petshop.db" />
+ </provider>
+
+ <sqlMaps>
+ <sqlMap resource="petshop-db/products.xml"/>
+ </sqlMaps>
+
+</sqlMapConfig>
\ No newline at end of file diff --git a/demos/sqlmap-sample/protected/runtime/application.xml/config.cache b/demos/sqlmap-sample/protected/runtime/application.xml/config.cache Binary files differnew file mode 100644 index 00000000..ce7bd76a --- /dev/null +++ b/demos/sqlmap-sample/protected/runtime/application.xml/config.cache diff --git a/demos/sqlmap-sample/protected/runtime/application.xml/global.cache b/demos/sqlmap-sample/protected/runtime/application.xml/global.cache new file mode 100644 index 00000000..b35e9768 --- /dev/null +++ b/demos/sqlmap-sample/protected/runtime/application.xml/global.cache @@ -0,0 +1 @@ +a:1:{s:35:"prado:securitymanager:validationkey";s:32:"e632288aebf1e51c0447ab4b701f1aa7";}
\ No newline at end of file diff --git a/demos/sqlmap-sample/protected/runtime/application.xml/sqlite.cache b/demos/sqlmap-sample/protected/runtime/application.xml/sqlite.cache Binary files differnew file mode 100644 index 00000000..be9b9cc0 --- /dev/null +++ b/demos/sqlmap-sample/protected/runtime/application.xml/sqlite.cache diff --git a/demos/sqlmap-sample/tests/PersonTest.php b/demos/sqlmap-sample/tests/PersonTest.php new file mode 100644 index 00000000..c40bffa0 --- /dev/null +++ b/demos/sqlmap-sample/tests/PersonTest.php @@ -0,0 +1,57 @@ +<?php
+
+class PersonTest extends UnitTestCase
+{
+ function testPersonList()
+ {
+ //try it
+ $people = TMapper::instance()->queryForList("SelectAll");
+
+ //test it
+ $this->assertNotNull($people, "Person list is not returned");
+ $this->assertTrue(count($people) > 0, "Person list is empty");
+ $person = $people[0];
+ $this->assertNotNull($person, "Person not returned");
+ }
+
+ function testPersonUpdate()
+ {
+ $expect = "wei";
+ $edited = "Nah";
+
+ //get it;
+ $person = TMapper::instance()->queryForObject("Select", 1);
+
+ //test it
+ $this->assertNotNull($person);
+ $this->assertEqual($expect, $person->FirstName);
+
+ //change it
+ $person->FirstName = $edited;
+ TMapper::instance()->update("Update", $person);
+
+ //get it again
+ $person = TMapper::instance()->queryForObject("Select", 1);
+
+ //test it
+ $this->assertEqual($edited, $person->FirstName);
+
+ //change it back
+ $person->FirstName = $expect;
+ TMapper::instance()->update("Update", $person);
+ }
+
+ function testPersonDelete()
+ {
+ //insert it
+ $person = new Person;
+ $person->ID = -1;
+ TMapper::instance()->insert("Insert", $person);
+
+ //delte it
+ $count = TMapper::instance()->delete("Delete", -1);
+ $this->assertEqual(1, $count);
+ }
+}
+
+?>
\ No newline at end of file diff --git a/demos/sqlmap-sample/tests/readme.txt b/demos/sqlmap-sample/tests/readme.txt new file mode 100644 index 00000000..c0d0afdb --- /dev/null +++ b/demos/sqlmap-sample/tests/readme.txt @@ -0,0 +1 @@ +The ''Data'' directory and ''Data/test.db'' must be writable by PHP for SQLite database to work.
\ No newline at end of file diff --git a/demos/sqlmap-sample/tests/run_tests.php b/demos/sqlmap-sample/tests/run_tests.php new file mode 100644 index 00000000..843d0a79 --- /dev/null +++ b/demos/sqlmap-sample/tests/run_tests.php @@ -0,0 +1,33 @@ +<?php
+
+//define simple test location
+define('SIMPLE_TEST', realpath('../../../tests/UnitTests/simpletest'));
+
+//define prado framework location
+define('PRADO', realpath('../../../framework'));
+
+//define directory that contains business objects
+define('MY_MODELS', realpath('../protected/business-objects'));
+
+require_once(SIMPLE_TEST.'/unit_tester.php');
+require_once(SIMPLE_TEST.'/reporter.php');
+require_once(PRADO.'/prado.php');
+require_once(MY_MODELS.'/Person.php');
+
+//supress strict warnings
+error_reporting(E_ALL);
+
+//import Data mapper
+Prado::using('System.DataAccess.SQLMap.TMapper');
+
+//Add tests
+$test = new GroupTest('SQLMap Tutorial tests');
+$test->addTestFile('PersonTest.php');
+if(SimpleReporter::inCli())
+ $reporter = new TextReporter();
+else
+ $reporter = new HtmlReporter();
+$test->run($reporter);
+
+
+?>
\ No newline at end of file diff --git a/demos/sqlmap-sample/tests/sqlmap.xml b/demos/sqlmap-sample/tests/sqlmap.xml new file mode 100644 index 00000000..3968fab4 --- /dev/null +++ b/demos/sqlmap-sample/tests/sqlmap.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8" ?>
+<sqlMapConfig>
+
+ <provider class="TAdodbProvider">
+ <datasource driver="sqlite" host="../protected/person-db/test.db" />
+ </provider>
+
+ <sqlMaps>
+ <sqlMap resource="../protected/person-db/person.xml"/>
+ <sqlMap resource="../protected/person-db/personHelper.xml"/>
+ </sqlMaps>
+
+</sqlMapConfig>
\ No newline at end of file |