Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
1e0d6757
Commit
1e0d6757
authored
Jun 13, 2006
by
doctrine
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Preliminary support for database views
parent
daeef41b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
215 additions
and
8 deletions
+215
-8
Query.php
Doctrine/Query.php
+44
-8
View.php
Doctrine/View.php
+103
-0
CacheQuerySqliteTestCase.php
tests/CacheQuerySqliteTestCase.php
+20
-0
ViewTestCase.php
tests/ViewTestCase.php
+44
-0
run.php
tests/run.php
+4
-0
No files found.
Doctrine/Query.php
View file @
1e0d6757
...
@@ -10,15 +10,15 @@ require_once("Access.php");
...
@@ -10,15 +10,15 @@ require_once("Access.php");
*/
*/
class
Doctrine_Query
extends
Doctrine_Access
{
class
Doctrine_Query
extends
Doctrine_Access
{
/**
/**
* @var array $fetchmodes an array containing all fetchmodes
* @var array $fetchmodes
an array containing all fetchmodes
*/
*/
private
$fetchModes
=
array
();
private
$fetchModes
=
array
();
/**
/**
* @var array $tables an array containing all the tables used in the query
* @var array $tables
an array containing all the tables used in the query
*/
*/
private
$tables
=
array
();
private
$tables
=
array
();
/**
/**
* @var array $collections an array containing all collections this parser has created/will create
* @var array $collections
an array containing all collections this parser has created/will create
*/
*/
private
$collections
=
array
();
private
$collections
=
array
();
...
@@ -26,19 +26,24 @@ class Doctrine_Query extends Doctrine_Access {
...
@@ -26,19 +26,24 @@ class Doctrine_Query extends Doctrine_Access {
private
$joins
=
array
();
private
$joins
=
array
();
/**
/**
* @var array $data fetched data
* @var array $data
fetched data
*/
*/
private
$data
=
array
();
private
$data
=
array
();
/**
/**
* @var Doctrine_Session $session Doctrine_Session object
* @var Doctrine_Session $session
Doctrine_Session object
*/
*/
private
$session
;
private
$session
;
/**
* @var Doctrine_View $view Doctrine_View object
*/
private
$view
;
private
$inheritanceApplied
=
false
;
private
$inheritanceApplied
=
false
;
private
$aggregate
=
false
;
private
$aggregate
=
false
;
/**
/**
* @var array $connectors component connectors
* @var array $connectors
component connectors
*/
*/
private
$connectors
=
array
();
private
$connectors
=
array
();
/**
/**
...
@@ -50,7 +55,7 @@ class Doctrine_Query extends Doctrine_Access {
...
@@ -50,7 +55,7 @@ class Doctrine_Query extends Doctrine_Access {
*/
*/
private
$tableIndexes
=
array
();
private
$tableIndexes
=
array
();
/**
/**
* @var array $dql DQL query string parts
* @var array $dql
DQL query string parts
*/
*/
protected
$dql
=
array
(
protected
$dql
=
array
(
"columns"
=>
array
(),
"columns"
=>
array
(),
...
@@ -85,6 +90,32 @@ class Doctrine_Query extends Doctrine_Access {
...
@@ -85,6 +90,32 @@ class Doctrine_Query extends Doctrine_Access {
public
function
__construct
(
Doctrine_Session
$session
)
{
public
function
__construct
(
Doctrine_Session
$session
)
{
$this
->
session
=
$session
;
$this
->
session
=
$session
;
}
}
/**
* @return Doctrine_Session
*/
public
function
getSession
()
{
return
$this
->
session
;
}
/**
* setView
* sets a database view this query object uses
* this method should only be called internally by doctrine
*
* @param Doctrine_View $view database view
* @return void
*/
public
function
setView
(
Doctrine_View
$view
)
{
$this
->
view
=
$view
;
}
/**
* getView
*
* @return Doctrine_View
*/
public
function
getView
()
{
return
$this
->
view
;
}
/**
/**
* clear
* clear
* resets all the variables
* resets all the variables
...
@@ -393,13 +424,18 @@ class Doctrine_Query extends Doctrine_Access {
...
@@ -393,13 +424,18 @@ class Doctrine_Query extends Doctrine_Access {
public
function
execute
(
$params
=
array
())
{
public
function
execute
(
$params
=
array
())
{
$this
->
data
=
array
();
$this
->
data
=
array
();
$this
->
collections
=
array
();
$this
->
collections
=
array
();
if
(
!
$this
->
view
)
$query
=
$this
->
getQuery
();
else
$query
=
$this
->
view
->
getSelectSql
();
switch
(
count
(
$this
->
tables
))
:
switch
(
count
(
$this
->
tables
))
:
case
0
:
case
0
:
throw
new
DQLException
();
throw
new
DQLException
();
break
;
break
;
case
1
:
case
1
:
$query
=
$this
->
getQuery
();
$keys
=
array_keys
(
$this
->
tables
);
$keys
=
array_keys
(
$this
->
tables
);
...
...
Doctrine/View.php
0 → 100644
View file @
1e0d6757
<?php
/**
* Doctrine_View
*
* this class represents a database view
*/
class
Doctrine_View
{
/**
* SQL DROP constant
*/
const
DROP
=
'DROP VIEW %s'
;
/**
* SQL CREATE constant
*/
const
CREATE
=
'CREATE VIEW %s AS %s'
;
/**
* SQL SELECT constant
*/
const
SELECT
=
'SELECT * FROM %s'
;
/**
* @var string $name
*/
protected
$name
;
/**
* @var Doctrine_Query $query
*/
protected
$query
;
/**
* @var PDO $dbh
*/
protected
$dbh
;
/**
* constructor
*
* @param Doctrine_Query $query
*/
public
function
__construct
(
Doctrine_Query
$query
)
{
$this
->
name
=
get_class
(
$this
);
$this
->
query
=
$query
;
$this
->
query
->
setView
(
$this
);
$this
->
dbh
=
$query
->
getSession
()
->
getDBH
();
}
/**
* simple get method for getting
* the associated query object
*
* @return Doctrine_Query
*/
public
function
getQuery
()
{
return
$this
->
query
;
}
/**
* returns the name of this view
*
* @return string
*/
public
function
getName
()
{
return
$this
->
name
;
}
/**
* returns the database handler
*
* @return PDO
*/
public
function
getDBH
()
{
return
$this
->
dbh
;
}
/**
* creates this view
*
* @return void
*/
public
function
create
()
{
$sql
=
sprintf
(
self
::
CREATE
,
$this
->
name
,
$this
->
query
->
getQuery
());
$this
->
dbh
->
query
(
$sql
);
}
/**
* drops this view
*
* @return void
*/
public
function
drop
()
{
$this
->
dbh
->
query
(
sprintf
(
self
::
DROP
,
$this
->
name
));
}
/**
* executes the view
*
* @return Doctrine_Collection
*/
public
function
execute
()
{
return
$this
->
query
->
execute
();
}
/**
* @return string
*/
public
function
getSelectSql
()
{
return
sprintf
(
self
::
SELECT
,
$this
->
name
);
}
}
?>
tests/CacheQuerySqliteTestCase.php
0 → 100644
View file @
1e0d6757
<?php
require_once
(
"UnitTestCase.php"
);
class
Doctrine_Cache_Query_SqliteTestCase
extends
Doctrine_UnitTestCase
{
public
function
setUp
()
{
parent
::
setUp
();
$this
->
manager
->
setAttribute
(
Doctrine
::
ATTR_CACHE
,
Doctrine
::
CACHE_NONE
);
$dir
=
$this
->
session
->
getAttribute
(
Doctrine
::
ATTR_CACHE_DIR
);
if
(
file_exists
(
$dir
.
DIRECTORY_SEPARATOR
.
"stats.cache"
))
unlink
(
$dir
.
DIRECTORY_SEPARATOR
.
"stats.cache"
);
$this
->
cache
=
new
Doctrine_Cache_Query_Sqlite
(
$this
->
objTable
);
$this
->
cache
->
deleteAll
();
}
public
function
testConstructor
()
{
}
}
?>
tests/ViewTestCase.php
0 → 100644
View file @
1e0d6757
<?php
class
MyView
extends
Doctrine_View
{
}
class
Doctrine_ViewTestCase
extends
Doctrine_UnitTestCase
{
public
function
testCreateView
()
{
$query
=
new
Doctrine_Query
(
$this
->
session
);
$query
->
from
(
'User'
);
$view
=
new
MyView
(
$query
);
$this
->
assertEqual
(
$view
->
getName
(),
'MyView'
);
$this
->
assertEqual
(
$view
->
getQuery
(),
$query
);
$this
->
assertEqual
(
$view
,
$query
->
getView
());
$this
->
assertTrue
(
$view
->
getDBH
()
instanceof
PDO
);
$success
=
true
;
try
{
$view
->
create
();
}
catch
(
Exception
$e
)
{
$success
=
false
;
}
$this
->
assertTrue
(
$success
);
$users
=
$view
->
execute
();
$count
=
$this
->
dbh
->
count
();
$this
->
assertTrue
(
$users
instanceof
Doctrine_Collection
);
$this
->
assertEqual
(
$users
->
count
(),
8
);
$this
->
assertEqual
(
$users
[
0
]
->
name
,
'zYne'
);
$this
->
assertEqual
(
$users
[
0
]
->
getState
(),
Doctrine_Record
::
STATE_CLEAN
);
$this
->
assertEqual
(
$count
,
$this
->
dbh
->
count
());
$success
=
true
;
try
{
$view
->
drop
();
}
catch
(
Exception
$e
)
{
$success
=
false
;
}
$this
->
assertTrue
(
$success
);
}
}
?>
tests/run.php
View file @
1e0d6757
...
@@ -17,6 +17,8 @@ require_once("PessimisticLockingTestCase.php");
...
@@ -17,6 +17,8 @@ require_once("PessimisticLockingTestCase.php");
require_once
(
"CacheSqliteTestCase.php"
);
require_once
(
"CacheSqliteTestCase.php"
);
require_once
(
"CollectionOffsetTestCase.php"
);
require_once
(
"CollectionOffsetTestCase.php"
);
require_once
(
"QueryTestCase.php"
);
require_once
(
"QueryTestCase.php"
);
require_once
(
"CacheQuerySqliteTestCase.php"
);
require_once
(
"ViewTestCase.php"
);
error_reporting
(
E_ALL
);
error_reporting
(
E_ALL
);
...
@@ -48,7 +50,9 @@ $test->addTestCase(new Doctrine_PessimisticLockingTestCase());
...
@@ -48,7 +50,9 @@ $test->addTestCase(new Doctrine_PessimisticLockingTestCase());
$test
->
addTestCase
(
new
Doctrine_QueryTestCase
());
$test
->
addTestCase
(
new
Doctrine_QueryTestCase
());
$test
->
addTestCase
(
new
Doctrine_ViewTestCase
());
//$test->addTestCase(new Doctrine_Cache_Query_SqliteTestCase());
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
//$test->addTestCase(new Doctrine_Cache_SqliteTestCase());
//$test->addTestCase(new Doctrine_Cache_SqliteTestCase());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment