yana

phpDocumentor v 1.4.0

Class DbExtractor

Description

«decorator» database Extractor
This decorator class is intended to create SQL DDL (data definition language) statements, and DML (data manipulation language) statements from YANA Framework databases and structure files.
For this task it provides functions which create specific SQL for various DBMS.
Example of usage:
  1.  // open new database connection
  2.  $db $YANA->connect('guestbook');
  3.  // create new instance
  4.  $dbe new DbExtractor($db);
  5.  // extract contents (here: use MySQL syntax)
  6.  $sql $dbe->createMySQL();
  7.  // print results
  8.  print implode("\n"$sql);
  9.  // extract the data only
  10.  $sql $dbe->createMySQL(false);
  11.  // extract the structure only
  12.  $sql $dbe->createMySQL(truefalse);
  • since: 2.9.6
  • access: public
Object
   |
   --DbCreator
      |
      --DbExtractor
Method Summary
  • DbExtractor DbExtractor (DbStream|FileDb $db)
  • array createDB2 ([bool $extractStructure = true], [bool $extractData = true])
  • array createMSAccess ([bool $extractStructure = true], [bool $extractData = true])
  • array createMSSQL ([bool $extractStructure = true], [bool $extractData = true])
  • array createMySQL ([bool $extractStructure = true], [bool $extractData = true])
  • array createOracleDB ([bool $extractStructure = true], [bool $extractData = true])
  • array createPostgreSQL ([bool $extractStructure = true], [bool $extractData = true])
  • string createXML ([bool $useForeignKeys = false], [string|array $structure = null], [string|array $table = null], [array $rows = null])
  • DbStructure importDbDesigner4 (string $dbDesignerConfig)
  • DbStructure importMDB2 (string $mdb2Schema)

Methods

create a new instance
DbExtractor DbExtractor ()
List of parameters:
Name Type Description
$db DbStream|FileDb a database resource
Description:
This class requires a database resource as input.
create SQL for IBM DB2
array createDB2 (
[bool $extractStructure = true], [bool $extractData = true]
)
List of parameters:
Name Type Description
$extractStructure bool
$extractData bool
Description:
Returns a numeric array of SQL statements. Each element is a single statement. If you want to send the result to a SQL file you should "implode()" the array to a string.
The result may include the data and structure of a database. Set the arguments $extractStructure or $extractData to bool(false) to exclude one or the other.
  • access: public

Redefinition of: DbCreator::createDB2()

create SQL for MS Access
array createMSAccess (
[bool $extractStructure = true], [bool $extractData = true]
)
List of parameters:
Name Type Description
$extractStructure bool
$extractData bool
Description:
Same as DbCreator::createMSSQL()
The result may include the data and structure of a database. Set the arguments $extractStructure or $extractData to bool(false) to exclude one or the other.

Redefinition of: DbCreator::createMSAccess()

create SQL for MS SQL Server
array createMSSQL (
[bool $extractStructure = true], [bool $extractData = true]
)
List of parameters:
Name Type Description
$extractStructure bool
$extractData bool
Description:
Returns a numeric array of SQL statements. Each element is a single statement. If you want to send the result to a SQL file you should "implode()" the array to a string.
The result may include the data and structure of a database. Set the arguments $extractStructure or $extractData to bool(false) to exclude one or the other.
  • access: public

Redefinition of: DbCreator::createMSSQL()

create SQL for MySQL
array createMySQL (
[bool $extractStructure = true], [bool $extractData = true]
)
List of parameters:
Name Type Description
$extractStructure bool
$extractData bool
Description:
Returns a numeric array of SQL statements. Each element is a single statement. If you want to send the result to a SQL file you should "implode()" the array to a string.
The result may include the data and structure of a database. Set the arguments $extractStructure or $extractData to bool(false) to exclude one or the other.
  • access: public

Redefinition of: DbCreator::createMySQL()

create SQL for Oracle
array createOracleDB (
[bool $extractStructure = true], [bool $extractData = true]
)
List of parameters:
Name Type Description
$extractStructure bool
$extractData bool
Description:
Returns a numeric array of SQL statements. Each element is a single statement. If you want to send the result to a SQL file you should "implode()" the array to a string.
The result may include the data and structure of a database. Set the arguments $extractStructure or $extractData to bool(false) to exclude one or the other.
  • access: public

Redefinition of: DbCreator::createOracleDB()

create SQL for PostgreSQL
array createPostgreSQL (
[bool $extractStructure = true], [bool $extractData = true]
)
List of parameters:
Name Type Description
$extractStructure bool
$extractData bool
Description:
Returns a numeric array of SQL statements. Each element is a single statement. If you want to send the result to a SQL file you should "implode()" the array to a string.
The result may include the data and structure of a database. Set the arguments $extractStructure or $extractData to bool(false) to exclude one or the other.
  • access: public

Redefinition of: DbCreator::createPostgreSQL()

create XML
string createXML (
[bool $useForeignKeys = false], [string|array $structure = null], [string|array $table = null], [array $rows = null]
)
List of parameters:
Name Type Description
$useForeignKeys bool toogle wether to export "flat" structure or use foreign keys to create recursive containers
$structure string|array limit output to certain structure file(s)
$table string|array limit output to certain table(s)
$rows array limit output to certain rows(s) e.g. array('tab1' => array(1, 2, 3))
Description:
This static function will export the content of the database to a xml string. It returns bool(false) on error.
You may limit the output to a certain table or structure file, by setting the arguments $structure and $table. Otherwise the whole database is exported, which is also the default behavior. You may set the argument $structure to NULL, if you just need $table.
Note that both arguments may also be provided as a list of files or tables.
You may set the argument $useForeignKeys to bool(true), if you want references (foreign keys) between tables to be respected. This way tables may be containers for other tables, where there is a relation between both.
To "resolve a foreign key relation" in this case actually means, each foreign key is interpreted as a parent-child relation between two tables. Each row of the child table (the referencing table) is then copied to it's parent row (the row in the referenced table, as identified by the value of the foreign key column in the current row of the child table).
Note, that a table may have multiple parents. This will result in multiple copies of the same row.
Also note, that this function does not detect circular references. However, this is not much of a restriction, as such references are not a legal construct in RDBMSs. Although some RDBMS allow such constructs, it would be "practically" impossible to add any data, without breaking referential integrity, because a row should not contain a checked reference to itself, while it does not exist.
Note: this may result in an error for DBMS that ignore referential integrity, like MyISAM tables in MySQL.
Here is an example to illustrate the behavior of this function. May "foo" and "bar" be tables, with "foo" having a property "bar_id", that is a foreign key, referencing "bar".
The following function call will output the XML representation of both tables:
  1.  print DbExtractor::createXML(truenullarray('foo''bar'));
The result would look something like this:
  1.  ... XML-head ...
  2.  <bar>
  3.    <item id="1">
  4.      <bar_id>1</bar_id>
  5.      <bar_value>0.0</bar_value>
  6.      <!-- here come some entries of table foo -->
  7.      <bar.foo>
  8.        <item id="2">
  9.          <foo_id>2</foo_id>
  10.          <bar_id>1</bar_id>
  11.          <!-- other values -->
  12.        </item>
  13.        <item id="5">
  14.          <foo_id>5</foo_id>
  15.          <bar_id>1</bar_id>
  16.          <!-- other values -->
  17.        </item>
  18.      </bar.foo>
  19.    </item>
  20.  </bar>
  • since: 2.9.7
  • access: public
import DBDesigner 4 configuration file to Yana structure files
DbStructure importDbDesigner4 (
string $dbDesignerConfig
)
List of parameters:
Name Type Description
$dbDesignerConfig string
Description:
The argument $dbDesignerConfig may either be a file name or XML file content.
This function will import the database structure from the given file and transform it into a compatible structure file, that can be used to create and modify databases via the framework's database API.
The function returns an instance of class DbStructure, or bool(false) on error.
  • access: public
import MDB2 schema to Yana structure files
DbStructure importMDB2 (
string $mdb2Schema
)
List of parameters:
Name Type Description
$mdb2Schema string
Description:
The argument $mdb2Schema may either be a file name or XML file content.
This function will import the database structure from the given file and transform it into a compatible structure file, that can be used to create and modify databases via the framework's database API.
The function returns an instance of class DbStructure, or bool(false) on error.
  • access: public
inherited from base classes

Inherited From DbCreator

Inherited From Object

Documentation generated on Sat, 03 Jan 2009 22:22:18 +0100 by phpDocumentor 1.4.0

yana author: Thomas MeyerHomepage: www.yanaframework.net