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
b6575631
Commit
b6575631
authored
Jan 25, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added tests for mssql import driver
parent
cdddf751
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
49 deletions
+75
-49
Export.php
lib/Doctrine/Export.php
+16
-40
Mssql.php
lib/Doctrine/Import/Mssql.php
+20
-8
MssqlTestCase.php
tests/Import/MssqlTestCase.php
+39
-1
No files found.
lib/Doctrine/Export.php
View file @
b6575631
...
...
@@ -145,7 +145,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
$queryFields
=
$this
->
getFieldDeclarationList
(
$fields
);
if
(
isset
(
$options
[
'primary'
])
&&
!
empty
(
$options
[
'primary'
]))
{
$queryFields
.=
', PRIMARY KEY('
.
implode
(
', '
,
array_values
(
$options
[
'primary'
]))
.
')'
;
$queryFields
.=
', PRIMARY KEY('
.
implode
(
', '
,
array_values
(
$options
[
'primary'
]))
.
')'
;
}
$name
=
$this
->
conn
->
quoteIdentifier
(
$name
,
true
);
...
...
@@ -191,11 +191,11 @@ class Doctrine_Export extends Doctrine_Connection_Module
{
$table
=
$this
->
conn
->
quoteIdentifier
(
$table
,
true
);
$name
=
$this
->
conn
->
quoteIdentifier
(
$this
->
conn
->
getIndexName
(
$name
),
true
);
$query
=
"ALTER TABLE
$table
ADD CONSTRAINT
$name
"
;
$query
=
'ALTER TABLE '
.
$table
.
' ADD CONSTRAINT '
.
$name
;
if
(
!
empty
(
$definition
[
'primary'
]))
{
$query
.=
' PRIMARY KEY'
;
$query
.=
' PRIMARY KEY'
;
}
elseif
(
!
empty
(
$definition
[
'unique'
]))
{
$query
.=
' UNIQUE'
;
$query
.=
' UNIQUE'
;
}
$fields
=
array
();
foreach
(
array_keys
(
$definition
[
'fields'
])
as
$field
)
{
...
...
@@ -207,7 +207,6 @@ class Doctrine_Export extends Doctrine_Connection_Module
/**
* Get the stucture of a field into an array
*
*
* @param string $table name of the table on which the index is to be created
* @param string $name name of the index to be created
* @param array $definition associative array that defines properties of the index to be created.
...
...
@@ -239,48 +238,14 @@ class Doctrine_Export extends Doctrine_Connection_Module
public
function
createIndex
(
$table
,
$name
,
array
$definition
)
{
return
$this
->
conn
->
execute
(
$this
->
createIndexSql
(
$table
,
$name
,
$definition
));
}
/**
* createForeignKey
*
* @param string $table name of the table on which the index is to be created
* @param string $name name of the foreign key to be created
* @param array $definition associative array that defines properties of the foreign key to be created.
*/
public
function
createForeignKey
(
$table
,
$name
,
array
$definition
)
{
}
/**
* Get the stucture of a field into an array
*
*
* @param string $table name of the table on which the index is to be created
* @param string $name name of the index to be created
* @param array $definition associative array that defines properties of the index to be created.
* Currently, only one property named FIELDS is supported. This property
* is also an associative with the names of the index fields as array
* indexes. Each entry of this array is set to another type of associative
* array that specifies properties of the index that are specific to
* each field.
*
* Currently, only the sorting property is supported. It should be used
* to define the sorting direction of the index. It may be set to either
* ascending or descending.
*
* Not all DBMS support index sorting direction configuration. The DBMS
* drivers of those that do not support it ignore this property. Use the
* function supports() to determine whether the DBMS driver can manage indexes.
*
* Example
* array(
* 'fields' => array(
* 'user_name' => array(
* 'sorting' => 'ascending'
* ),
* 'last_login' => array()
* )
* )
* @see Doctrine_Export::createIndex()
* @return string
*/
public
function
createIndexSql
(
$table
,
$name
,
array
$definition
)
...
...
@@ -296,6 +261,17 @@ class Doctrine_Export extends Doctrine_Connection_Module
$query
.=
' ('
.
implode
(
', '
,
$fields
)
.
')'
;
return
$query
;
}
/**
* createForeignKey
*
* @param string $table name of the table on which the index is to be created
* @param string $name name of the foreign key to be created
* @param array $definition associative array that defines properties of the foreign key to be created.
*/
public
function
createForeignKey
(
$table
,
$name
,
array
$definition
)
{
}
/**
* alter an existing table
...
...
lib/Doctrine/Import/Mssql.php
View file @
b6575631
...
...
@@ -54,7 +54,7 @@ class Doctrine_Import_Mssql extends Doctrine_Import
*/
public
function
listTableColumns
(
$table
)
{
$sql
=
'EXEC sp_columns @table_name = '
.
$this
->
quoteIdentifier
(
$tabl
e
);
$sql
=
'EXEC sp_columns @table_name = '
.
$this
->
conn
->
quoteIdentifier
(
$table
,
tru
e
);
$result
=
$this
->
conn
->
fetchAssoc
(
$sql
);
$columns
=
array
();
...
...
@@ -102,7 +102,20 @@ class Doctrine_Import_Mssql extends Doctrine_Import
{
$sql
=
"SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"
;
return
$this
->
dbh
->
fetchColumn
(
$sql
);
return
$this
->
conn
->
fetchColumn
(
$sql
);
}
/**
* lists all triggers
*
* @return array
*/
public
function
listTriggers
()
{
$query
=
"SELECT name FROM sysobjects WHERE xtype = 'TR'"
;
$result
=
$this
->
conn
->
fetchColumn
(
$query
);
return
$result
;
}
/**
* lists table triggers
...
...
@@ -113,10 +126,7 @@ class Doctrine_Import_Mssql extends Doctrine_Import
public
function
listTableTriggers
(
$table
)
{
$table
=
$this
->
conn
->
quote
(
$table
,
'text'
);
$query
=
"SELECT name FROM sysobjects WHERE xtype = 'TR'"
;
if
(
!
is_null
(
$table
))
{
$query
.=
"AND object_name(parent_obj) =
$table
"
;
}
$query
=
"SELECT name FROM sysobjects WHERE xtype = 'TR' AND object_name(parent_obj) = "
.
$table
;
$result
=
$this
->
conn
->
fetchColumn
(
$query
);
...
...
@@ -143,11 +153,13 @@ class Doctrine_Import_Mssql extends Doctrine_Import
}
$table
=
$this
->
conn
->
quote
(
$table
,
'text'
);
$query
=
'EXEC sp_statistics @table_name = '
.
$table
;
$indexes
=
$this
->
conn
->
queryCol
(
$query
,
'text'
,
$keyName
);
$indexes
=
$this
->
conn
->
fetchColumn
(
$query
,
$keyName
);
$query
=
'EXEC sp_pkeys @table_name = '
.
$table
;
$pkAll
=
$this
->
conn
->
queryCol
(
$query
,
'text'
,
$pkName
);
$pkAll
=
$this
->
conn
->
fetchColumn
(
$query
,
$pkName
);
$result
=
array
();
foreach
(
$indexes
as
$index
)
{
if
(
!
in_array
(
$index
,
$pkAll
)
&&
$index
!=
null
)
{
$result
[]
=
$this
->
_fixIndexName
(
$index
);
...
...
tests/Import/MssqlTestCase.php
View file @
b6575631
...
...
@@ -30,5 +30,43 @@
* @since 1.0
* @version $Revision$
*/
class
Doctrine_Import_Mssql_TestCase
extends
Doctrine_UnitTestCase
{
class
Doctrine_Import_Mssql_TestCase
extends
Doctrine_UnitTestCase
{
public
function
testListSequencesExecutesSql
()
{
$this
->
import
->
listSequences
(
'table'
);
$this
->
assertEqual
(
$this
->
adapter
->
pop
(),
"SELECT name FROM sysobjects WHERE xtype = 'U'"
);
}
public
function
testListTableColumnsExecutesSql
()
{
$this
->
conn
->
setAttribute
(
Doctrine
::
ATTR_QUOTE_IDENTIFIER
,
false
);
$this
->
import
->
listTableColumns
(
'table'
);
$this
->
assertEqual
(
$this
->
adapter
->
pop
(),
"EXEC sp_columns @table_name = table"
);
}
public
function
testListTablesExecutesSql
()
{
$this
->
import
->
listTables
();
$this
->
assertEqual
(
$this
->
adapter
->
pop
(),
"SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"
);
}
public
function
testListTriggersExecutesSql
()
{
$this
->
import
->
listTriggers
();
$this
->
assertEqual
(
$this
->
adapter
->
pop
(),
"SELECT name FROM sysobjects WHERE xtype = 'TR'"
);
}
public
function
testListTableTriggersExecutesSql
()
{
$this
->
import
->
listTableTriggers
(
'table'
);
$this
->
assertEqual
(
$this
->
adapter
->
pop
(),
"SELECT name FROM sysobjects WHERE xtype = 'TR' AND object_name(parent_obj) = 'table'"
);
}
public
function
testListViewsExecutesSql
()
{
$this
->
import
->
listViews
();
$this
->
assertEqual
(
$this
->
adapter
->
pop
(),
"SELECT name FROM sysobjects WHERE xtype = 'V'"
);
}
}
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