├── tmp └── .gitkeep ├── .gitignore ├── example-05.php ├── whiteboard.php ├── example-18.php ├── example-06.php ├── example-11.php ├── example-14.php ├── example-09.php ├── example-08.php ├── example-21.php ├── setup ├── down.php ├── up.php └── vendor │ ├── sqlite.php │ ├── postgresql.php │ ├── mysql.php │ ├── sqlserver.php │ ├── ibm-db2.php │ ├── common.php │ └── oracle.php ├── example-13.php ├── example-07.php ├── example-19.php ├── example-12.php ├── example-01.php ├── example-20.php ├── bootstrap.dist.php ├── example-04.php ├── example-03.php ├── example-15.php ├── example-02.php ├── example-17.php ├── example-10.php ├── example-16.php ├── README.md ├── example-22.php └── includes └── functions.php /tmp/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bootstrap.php 2 | tmp/sqlite.db 3 | -------------------------------------------------------------------------------- /example-05.php: -------------------------------------------------------------------------------- 1 | driver->getConnection(); 9 | $r = $c->execute('SELECT * FROM "artist"'); 10 | var_dump($r); 11 | -------------------------------------------------------------------------------- /example-18.php: -------------------------------------------------------------------------------- 1 | getColumns()); -------------------------------------------------------------------------------- /example-06.php: -------------------------------------------------------------------------------- 1 | select(array('id' => 2)); 12 | $row = $rowset->current(); 13 | 14 | $name = $row['name']; 15 | $name2 = $row->name; 16 | assert_example_works($name == 'Linkin Park' && $name2 == 'Linkin Park'); -------------------------------------------------------------------------------- /example-11.php: -------------------------------------------------------------------------------- 1 | configure(new Zend\Di\Configuration(array( 7 | 'instance' => array( 8 | 'Zend\Db\Adapter\Adapter' => array( 9 | 'parameters' => array( 10 | 'driver' => $dbconfig 11 | ) 12 | ) 13 | ) 14 | ))); 15 | 16 | //var_dump($di->instanceManager()); 17 | $db = $di->get('Zend\Db\Adapter\Adapter'); 18 | 19 | echo $db->platform->getName() . PHP_EOL; 20 | -------------------------------------------------------------------------------- /example-14.php: -------------------------------------------------------------------------------- 1 | select(function (Select $select) { 11 | $select->where->like('name', 'Link%'); 12 | }); 13 | $row = $rowset->current(); 14 | 15 | $name = $row['name']; 16 | $name2 = $row->name; 17 | 18 | assert_example_works($name == 'Linkin Park' && $name2 == 'Linkin Park'); -------------------------------------------------------------------------------- /example-09.php: -------------------------------------------------------------------------------- 1 | delete(array('id' => 2)); 9 | 10 | assert_example_works($result === 1, true); 11 | 12 | $artistTable = new Zend\Db\TableGateway\TableGateway('artist', $adapter); 13 | $rowset = $artistTable->select(array('id' => 2)); 14 | $row = $rowset->current(); 15 | 16 | assert_example_works($row == false); 17 | -------------------------------------------------------------------------------- /example-08.php: -------------------------------------------------------------------------------- 1 | update(array('name' => 'New Artist'), array('id' => 2)); 9 | 10 | assert_example_works($result === 1, true); 11 | 12 | $artistTable = new Zend\Db\TableGateway\TableGateway('artist', $adapter); 13 | $rowset = $artistTable->select(array('id' => 2)); 14 | $row = $rowset->current(); 15 | 16 | $name = $row['name']; 17 | assert_example_works($name == 'New Artist'); -------------------------------------------------------------------------------- /example-21.php: -------------------------------------------------------------------------------- 1 | getQueryResultSetPrototype()->buffer(); // default ResultSet is Zend\Db\ResultSet\ResultSet 7 | 8 | $resultSet = $adapter->query( 9 | 'SELECT * FROM ' . $adapter->platform->quoteIdentifier('artist'), 10 | $adapter::QUERY_MODE_EXECUTE 11 | ); 12 | 13 | foreach ($resultSet as $i => $row) { 14 | echo $i . ': ' . $row['name'] . PHP_EOL; 15 | } 16 | echo PHP_EOL; 17 | foreach ($resultSet as $i => $row) { 18 | echo $i . ': ' . $row['name'] . PHP_EOL; 19 | } 20 | -------------------------------------------------------------------------------- /setup/down.php: -------------------------------------------------------------------------------- 1 | getPlatform()->getName(); 6 | 7 | $vendorData = include __DIR__ . '/vendor/' . str_replace(' ', '-', strtolower($platform)) . '.php'; 8 | 9 | try { 10 | foreach ($vendorData['schema_down'] as $schemaStmt) { 11 | try { 12 | $adapter->query($schemaStmt, $adapter::QUERY_MODE_EXECUTE); 13 | } catch (\Exception $e) { 14 | echo $schemaStmt . ' FAILED DUE TO ' . $e->getMessage() . PHP_EOL; 15 | } 16 | } 17 | } catch (\Exception $e) { 18 | echo $e->getMessage(); 19 | exit(1); 20 | } 21 | -------------------------------------------------------------------------------- /example-13.php: -------------------------------------------------------------------------------- 1 | equalTo('id', 1)->OR->equalTo('id', 2); 9 | $where->OR 10 | ->NEST->like('name', 'Ralph%')->OR->greaterThanOrEqualTo('age', 30)->AND->lessThanOrEqualTo('age', 50)->UNNEST 11 | ->literal('foo = ?', 'bar'); 12 | 13 | $target =<<= '30' AND "age" <= '50') AND foo = 'bar' 15 | EOS; 16 | 17 | $select = new Zend\Db\Sql\Select('foo'); 18 | $select->where($where); 19 | 20 | assert_example_works($target == $select->getSqlString()); -------------------------------------------------------------------------------- /example-07.php: -------------------------------------------------------------------------------- 1 | insert(array( 9 | 'name' => 'New Artist', 10 | 'history' => 'This is the history' 11 | )); 12 | 13 | $id = $artistTable->getLastInsertValue(); 14 | 15 | if ($id == null && $adapter->getPlatform()->getName() == 'PostgreSQL') { 16 | $id = $adapter->getDriver()->getConnection()->getLastGeneratedValue('artist_id_seq'); 17 | } 18 | 19 | assert_example_works($result === 1, true); 20 | 21 | $artistTable = new Zend\Db\TableGateway\TableGateway('artist', $adapter); 22 | $rowset = $artistTable->select(array('id' => $id)); 23 | $row = $rowset->current(); 24 | 25 | $name = $row['name']; 26 | assert_example_works($name == 'New Artist'); -------------------------------------------------------------------------------- /example-19.php: -------------------------------------------------------------------------------- 1 | select(); 13 | $subselect->from('artist') 14 | ->columns(array()) // no columns from main table 15 | ->join('album', 'artist.id = album.artist_id', array('title', 'release_date')) 16 | //->order(array('release_date', 'title')) 17 | ->where->like('artist.name', '%Brit%'); 18 | 19 | $select = $sql->select(); 20 | $select->from(array('t' => $subselect))->columns(array('c' => new Sql\Expression('COUNT(1)'))); 21 | 22 | $statement = $sql->prepareStatementForSqlObject($select); 23 | 24 | $result = $statement->execute(); 25 | $row = $result->current(); 26 | 27 | assert_example_works($row['c'] == 7); 28 | -------------------------------------------------------------------------------- /example-12.php: -------------------------------------------------------------------------------- 1 | setSelectResultPrototype( 11 | // new Zend\Db\ResultSet\ResultSet(new Zend\Db\RowGateway\RowGateway($artistTable, 'id')) 12 | // ); 13 | 14 | 15 | // find and update 16 | $rowset = $artistTable->select(array('id' => 2)); 17 | 18 | // make sure all rows come back and RowGateway 19 | $rowset->setArrayObjectPrototype(new Zend\Db\RowGateway\RowGateway('id', 'artist', $adapter)); 20 | 21 | $row = $rowset->current(); 22 | 23 | $row['name'] = 'New Artist'; // array notation 24 | $affected = $row->save(); 25 | 26 | // check 27 | $rowset = $artistTable->select(array('id' => 2)); 28 | $row = $rowset->current(); 29 | 30 | assert_example_works($row->name == 'New Artist'); // object notation -------------------------------------------------------------------------------- /example-01.php: -------------------------------------------------------------------------------- 1 | platform->quoteIdentifier('artist') 19 | . ' WHERE ' . $adapter->platform->quoteIdentifier('id') . ' = ' . $adapter->driver->formatParameterName('id'); 20 | 21 | /* @var $statement \Zend\Db\Adapter\Driver\StatementInterface */ 22 | $statement = $adapter->query($sql); 23 | $parameters = array('id' => 2); 24 | 25 | /* @var $results Zend\Db\ResultSet\ResultSet */ 26 | $results = $statement->execute($parameters); 27 | 28 | $row = $results->current(); 29 | $name = $row['name']; 30 | assert_example_works($name == 'Linkin Park'); -------------------------------------------------------------------------------- /example-20.php: -------------------------------------------------------------------------------- 1 | select(); 13 | $subselect->from('artist') 14 | ->columns(array('name')) 15 | ->join('album', 'artist.id = album.artist_id', array()) 16 | ->where->greaterThan('release_date', '2005-01-01'); 17 | 18 | 19 | $select = $sql->select(); 20 | $select->from('artist') 21 | ->order(array('name' => Sql\Select::ORDER_ASCENDING)) 22 | ->where 23 | ->like('name', 'L%') 24 | ->AND->in('name', $subselect); 25 | 26 | $statement = $sql->prepareStatementForSqlObject($select); 27 | 28 | $result = $statement->execute(); 29 | 30 | $rows = array_values(iterator_to_array($result)); 31 | 32 | assert_example_works( 33 | count($rows) == 2 34 | && $rows[0]['name'] == 'Lady Gaga' 35 | && $rows[1]['name'] == 'Linkin Park' 36 | ); 37 | -------------------------------------------------------------------------------- /bootstrap.dist.php: -------------------------------------------------------------------------------- 1 | register(); 15 | 16 | $dbconfig = array( 17 | 18 | // Sqlite Configuration 19 | 'driver' => 'Pdo', 20 | 'dsn' => 'sqlite:' . __DIR__ . '/tmp/sqlite.db', 21 | 22 | // Mysqli Configuration 23 | //'driver' => 'Mysqli', 24 | //'hostname' => 'localhost', 25 | //'username' => 'developer', 26 | //'password' => 'developer', 27 | //'database' => 'zend_db_example', 28 | //'table_type' => 'InnoDB' 29 | 30 | // Sqlsrv Configuration 31 | //'driver' => 'Sqlsrv', 32 | //'hostname' => 'MYHOSTNAME-PC\SQLEXPRESS', 33 | //'UID' => 'developer', 34 | //'PWD' => 'developer', 35 | //'Database' => 'zend_db_example' 36 | 37 | ); 38 | 39 | return new DbAdapter($dbconfig); 40 | -------------------------------------------------------------------------------- /setup/up.php: -------------------------------------------------------------------------------- 1 | getPlatform()->getName(); 6 | 7 | $vendorData = include __DIR__ . '/vendor/' . str_replace(' ', '-', strtolower($platform)) . '.php'; 8 | 9 | try { 10 | foreach ($vendorData['schema_down'] as $schemaStmt) { 11 | try { 12 | $adapter->query($schemaStmt, $adapter::QUERY_MODE_EXECUTE); 13 | } catch (\Exception $e) { 14 | echo $schemaStmt . ' FAILED DUE TO ' . $e->getMessage() . PHP_EOL; 15 | } 16 | } 17 | } catch (\Exception $e) { 18 | echo $e->getMessage(); 19 | exit(1); 20 | } 21 | 22 | try { 23 | foreach ($vendorData['schema_up'] as $schemaStmt) { 24 | try { 25 | $adapter->query($schemaStmt, $adapter::QUERY_MODE_EXECUTE); 26 | } catch (\Exception $e) { 27 | echo $schemaStmt . ' FAILED DUE TO ' . $e->getMessage() . PHP_EOL; 28 | } 29 | } 30 | } catch (\Exception $e) { 31 | echo $e->getMessage(); 32 | exit(1); 33 | } 34 | 35 | 36 | -------------------------------------------------------------------------------- /example-04.php: -------------------------------------------------------------------------------- 1 | platform->quoteIdentifier($name); }; 11 | $fp = function($name) use ($adapter) { return $adapter->driver->formatParameterName($name); }; 12 | 13 | $sql = 'DELETE FROM ' . $qi('artist') 14 | . ' WHERE ' . $qi('id') . ' = ' . $fp('id'); 15 | 16 | /* @var $statement Zend\Db\Adapter\DriverStatementInterface */ 17 | $statement = $adapter->query($sql); 18 | 19 | $parameters = array( 20 | 'id' => 1 21 | ); 22 | 23 | $statement->execute($parameters); 24 | 25 | // DATA INSERTED, NOW CHECK 26 | 27 | /* @var $statement Zend\Db\Adapter\DriverStatementInterface */ 28 | $statement = $adapter->query('SELECT * FROM ' 29 | . $qi('artist') 30 | . ' WHERE id = ' . $fp('id')); 31 | 32 | /* @var $results Zend\Db\ResultSet\ResultSet */ 33 | $results = $statement->execute(array('id' => 1)); 34 | 35 | $row = $results->current(); 36 | assert_example_works($row == false); 37 | -------------------------------------------------------------------------------- /example-03.php: -------------------------------------------------------------------------------- 1 | platform->quoteIdentifier($name); }; 11 | $fp = function($name) use ($adapter) { return $adapter->driver->formatParameterName($name); }; 12 | 13 | $sql = 'UPDATE ' . $qi('artist') 14 | . ' SET ' . $qi('name') . ' = ' . $fp('name') 15 | . ' WHERE ' . $qi('id') . ' = ' . $fp('id'); 16 | 17 | /* @var $statement Zend\Db\Adapter\DriverStatementInterface */ 18 | $statement = $adapter->query($sql); 19 | 20 | $parameters = array( 21 | 'name' => 'Updated Artist', 22 | 'id' => 1 23 | ); 24 | 25 | $statement->execute($parameters); 26 | 27 | // DATA INSERTED, NOW CHECK 28 | 29 | /* @var $statement Zend\Db\Adapter\DriverStatementInterface */ 30 | $statement = $adapter->query('SELECT * FROM ' 31 | . $qi('artist') 32 | . ' WHERE id = ' . $fp('id')); 33 | 34 | /* @var $results Zend\Db\ResultSet\ResultSet */ 35 | $results = $statement->execute(array('id' => 1)); 36 | 37 | $row = $results->current(); 38 | $name = $row['name']; 39 | assert_example_works($name == 'Updated Artist'); -------------------------------------------------------------------------------- /example-15.php: -------------------------------------------------------------------------------- 1 | from('artist') 12 | ->columns(array()) // no columns from main table 13 | ->join('album', 'artist.id = album.artist_id', array('title', 'release_date')) 14 | ->order(array('release_date', 'title')) 15 | ->where->like('artist.name', '%Brit%'); 16 | 17 | $statement = $adapter->createStatement(); 18 | $select->prepareStatement($adapter, $statement); 19 | 20 | $resultSet = new ResultSet(); 21 | $resultSet->initialize($statement->execute()); 22 | 23 | $albums = array(); 24 | foreach ($resultSet as $row) { 25 | $albums[] = $row->title . ' released on: ' . date('Y-m-d', strtotime($row->release_date)); 26 | } 27 | 28 | assert_example_works( 29 | $albums == array( 30 | 0 => '...Baby One More Time released on: 1999-02-14', 31 | 1 => 'Oops!... I Did It Again released on: 2000-10-10', 32 | 2 => 'Britney released on: 2001-04-06', 33 | 3 => 'Blackout released on: 2007-10-10', 34 | 4 => 'Circus released on: 2008-11-23', 35 | 5 => 'Femme Fatale released on: 2011-10-10', 36 | 6 => 'In the Zone released on: 2011-10-10', 37 | )); 38 | -------------------------------------------------------------------------------- /example-02.php: -------------------------------------------------------------------------------- 1 | platform->quoteIdentifier($name); }; 12 | $fp = function($name) use ($adapter) { return $adapter->driver->formatParameterName($name); }; 13 | 14 | $sql = 'INSERT INTO ' 15 | . $qi('artist') 16 | . ' (' . $qi('name') . ', ' . $qi('history') . ') VALUES (' 17 | . $fp('name') . ', ' . $fp('history') . ')'; 18 | 19 | /* @var $statement Zend\Db\Adapter\Driver\StatementInterface */ 20 | $statement = $adapter->query($sql); 21 | 22 | $parameters = array( 23 | 'name' => 'New Artist', 24 | 'history' => 'This is the history' 25 | ); 26 | 27 | $result = $statement->execute($parameters); 28 | 29 | $id = (int) $result->getGeneratedValue(); 30 | 31 | // DATA INSERTED, NOW CHECK 32 | 33 | /* @var $statement Zend\Db\Adapter\Driver\StatementInterface */ 34 | $statement = $adapter->query('SELECT * FROM ' 35 | . $qi('artist') 36 | . ' WHERE ' . $qi('id') . ' = ' . $fp('id')); 37 | 38 | /* @var $results Zend\Db\ResultSet\ResultSet */ 39 | $results = $statement->execute(array('id' => $id)); 40 | 41 | $row = $results->current(); 42 | $name = $row['name']; 43 | 44 | assert_example_works($name == 'New Artist'); -------------------------------------------------------------------------------- /example-17.php: -------------------------------------------------------------------------------- 1 | select(array('id' => 2)); 20 | $rows->getDataSource()->buffer(); // buffer result set (only does something for mysqli) 21 | 22 | /** @var $row \Zend\Db\RowGateway\RowGateway */ 23 | $row = $rows->current(); 24 | 25 | assert_example_works($row->name == 'Linkin Park' && $row instanceof \Zend\Db\RowGateway\RowGateway, true); 26 | 27 | // update the row 28 | $row['name'] = 'New Artist'; 29 | $row->save(); 30 | 31 | unset($row, $rows, $artistTable); 32 | 33 | 34 | // ensure, separately, that that worked 35 | $statement = $adapter->query('SELECT * FROM ' 36 | . $adapter->platform->quoteIdentifier('artist') 37 | . ' WHERE id = ' . $adapter->driver->formatParameterName('id')); 38 | $result = $statement->execute(array('id' => 2)); 39 | $row = $result->current(); 40 | assert_example_works($row['name'] == 'New Artist' && is_array($row)); 41 | -------------------------------------------------------------------------------- /example-10.php: -------------------------------------------------------------------------------- 1 | getTableNames(); 10 | 11 | foreach ($tableNames as $tableName) { 12 | echo 'In Table ' . $tableName . PHP_EOL; 13 | 14 | $table = $metadata->getTable($tableName); 15 | 16 | 17 | echo ' With columns: ' . PHP_EOL; 18 | foreach ($table->getColumns() as $column) { 19 | echo ' ' . $column->getName() 20 | . ' -> ' . $column->getDataType() 21 | . PHP_EOL; 22 | } 23 | 24 | echo PHP_EOL; 25 | echo ' With constraints: ' . PHP_EOL; 26 | 27 | foreach ($metadata->getConstraints($tableName) as $constraint) { 28 | /** @var $constraint Zend\Db\Metadata\Object\ConstraintObject */ 29 | echo ' ' . $constraint->getName() 30 | . ' -> ' . $constraint->getType() 31 | . PHP_EOL; 32 | if (!$constraint->hasColumns()) { 33 | continue; 34 | } 35 | echo ' column: ' . implode(', ', $constraint->getColumns()); 36 | if ($constraint->isForeignKey()) { 37 | $fkCols = array(); 38 | foreach ($constraint->getReferencedColumns() as $refColumn) { 39 | $fkCols[] = $constraint->getReferencedTableName() . '.' . $refColumn; 40 | } 41 | echo ' => ' . implode(', ', $fkCols); 42 | } 43 | echo PHP_EOL; 44 | 45 | } 46 | 47 | echo '----' . PHP_EOL; 48 | } 49 | -------------------------------------------------------------------------------- /example-16.php: -------------------------------------------------------------------------------- 1 | select(); 12 | $select->from('artist') 13 | ->columns(array()) // no columns from main table 14 | ->join('album', 'artist.id = album.artist_id', array('title', 'release_date')) 15 | ->order(array('release_date', 'title')) 16 | ->limit(2)->offset(0) 17 | ->where->like('artist.name', '%Brit%'); 18 | 19 | // prepare statement in a platform specific way 20 | $statement = $sql->prepareStatementForSqlObject($select); 21 | $container = $statement->getParameterContainer(); 22 | 23 | // create iterable result set 24 | $resultSet = new ResultSet(); 25 | 26 | // as we iterate bind the new offset to the existing statement 27 | foreach (array(0, 2, 4) as $offset) { 28 | 29 | $container->offsetSet('offset', $offset); 30 | $resultSet->initialize($statement->execute()); 31 | 32 | $output = ''; 33 | foreach ($resultSet->toArray() as $row) { 34 | $output .= '|' . $row['title'] . '|'; 35 | } 36 | 37 | switch ($offset) { 38 | case 0: 39 | assert_example_works($output === '|...Baby One More Time||Oops!... I Did It Again|', true); 40 | break; 41 | case 2: 42 | assert_example_works($output === '|Britney||Blackout|', true); 43 | break; 44 | case 4: 45 | assert_example_works($output === '|Circus||Femme Fatale|'); 46 | break; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | README 2 | ====== 3 | 4 | Introduction 5 | ------------ 6 | 7 | This repository show's off Zend\Db's feature-set via a simple schema and simple tasks. The schema's are located in `setup/vendor` and are tailored to setup a scheme in a vendor specific way. So, the first thing you'll need to do is run the setup scripts. If you decide you want to run them against something other than Sqlite, first copy the bootstrap and setup the proper credentials. 8 | 9 | Setup: 10 | ------ 11 | 12 | First, you'll need to 13 | 14 | setup/up.php 15 | 16 | If you want to run against something other than Sqlite, copy the bootstrap, then fill out the credentials in the appropriate section: 17 | 18 | cp bootstrap.dist.php bootstrap.php 19 | < < edit bootstrap.php > > 20 | 21 | To destroy a schema 22 | 23 | setup/down.php 24 | 25 | 26 | Examples: 27 | --------- 28 | 29 | 1 - 4. (working) SELECT, INSERT, UPDATE, DELETE through adapter using array based parameritized query. These scripts are utilizing the Adapter and Platform API's to produce vendor agnostic queries. 30 | 31 | php example-01.php 32 | php example-02.php 33 | php example-03.php 34 | php example-04.php 35 | 36 | 5\. Demonstrate adapter exception handling (not working.) 37 | 38 | n/a 39 | 40 | 6 - 9. TableGateway examples showing basic select(), insert(), update(), and delete(). 41 | 42 | php example-06.php 43 | php example-07.php 44 | php example-08.php 45 | php example-09.php 46 | 47 | Unpacking the Phar: 48 | ------------------- 49 | 50 | Currently, this master repository is using an up to date phar of just Zend_Db. To extract these files for usage, use the phar.phar utility: 51 | 52 | phar.phar extract -f Zend_Db-2.0.0dev.phar 53 | 54 | Linking to your checked out code: 55 | 56 | cp bootstrap.dist.php bootstrap.php 57 | 58 | edit bootstrap with: 59 | 60 | // include 'Zend_Db-2.0.0dev.phar'; 61 | require_once '/path/to/ZF2/library/Zend/Loader/StandardAutoloader.php'; 62 | $autoloader = new Autoloader; 63 | $autoloader->register(); 64 | 65 | -------------------------------------------------------------------------------- /setup/vendor/sqlite.php: -------------------------------------------------------------------------------- 1 | array( 7 | 'CREATE TABLE IF NOT EXISTS "album" ( 8 | "id" INTEGER PRIMARY KEY, 9 | "artist_id" int(11) NOT NULL, 10 | "title" varchar(255) NOT NULL, 11 | "release_date" date NOT NULL, 12 | FOREIGN KEY ("artist_id") REFERENCES "artist"("id") 13 | );', 14 | 'CREATE TABLE IF NOT EXISTS "artist" ( 15 | "id" INTEGER PRIMARY KEY, 16 | "name" varchar(255) NOT NULL, 17 | "history" text 18 | );', 19 | 'CREATE TABLE IF NOT EXISTS "genre" ( 20 | "id" INTEGER PRIMARY KEY, 21 | "parent_id" int(11) DEFAULT NULL, 22 | "name" varchar(255) NOT NULL, 23 | UNIQUE ("name"), 24 | FOREIGN KEY ("parent_id") REFERENCES "genre" ("id") 25 | );', 26 | 'CREATE TABLE IF NOT EXISTS "artist_genre" ( 27 | "artist_id" int(11) NOT NULL, 28 | "genre_id" int(11) NOT NULL, 29 | "added_on" date NOT NULL, 30 | PRIMARY KEY ("artist_id","genre_id"), 31 | FOREIGN KEY ("artist_id") REFERENCES "artist" ("id"), 32 | FOREIGN KEY ("genre_id") REFERENCES "genre" ("id") 33 | );', 34 | 'CREATE TABLE IF NOT EXISTS "track" ( 35 | "id" INTEGER PRIMARY KEY, 36 | "artist_id" int(11) DEFAULT NULL, 37 | "album_id" int(11) DEFAULT NULL, 38 | "number" int(11) DEFAULT NULL, 39 | "title" varchar(255) NOT NULL, 40 | "length" int(11) NOT NULL, 41 | FOREIGN KEY ("artist_id") REFERENCES "artist" ("id"), 42 | FOREIGN KEY ("album_id") REFERENCES "album" ("id") 43 | );' 44 | ), 45 | 'schema_down' => array( 46 | 'DROP TABLE IF EXISTS "album"', 47 | 'DROP TABLE IF EXISTS "artist"', 48 | 'DROP TABLE IF EXISTS "genre"', 49 | 'DROP TABLE IF EXISTS "artist_genre"', 50 | 'DROP TABLE IF EXISTS "track"' 51 | ), 52 | 'data_down' => array( 53 | 'DELETE FROM "album"', 54 | 'DELETE FROM "artist"', 55 | 'DELETE FROM "artist_genre"', 56 | 'DELETE FROM "genre"', 57 | 'DELETE FROM "track"', 58 | ) 59 | )); -------------------------------------------------------------------------------- /example-22.php: -------------------------------------------------------------------------------- 1 | attach('ArtistTable', 'preInsert', function ($event) { 20 | /** @var $target TableGateway */ 21 | $target = $event->getTarget(); 22 | echo 'This is before Insert of the ' . get_class($target) . ' for table ' . $target->getTable() . PHP_EOL; 23 | echo 'With param names: ' . PHP_EOL; 24 | var_dump(array_keys($event->getParams())); 25 | }); 26 | 27 | $sem->attach('Zend\Db\TableGateway\TableGateway', 'postInsert', function ($event) { 28 | /** @var $target TableGateway */ 29 | $target = $event->getTarget(); 30 | echo 'This is after Insert of the ' . get_class($target) . ' for table ' . $target->getTable() . PHP_EOL; 31 | echo 'With params names: ' . PHP_EOL; 32 | var_dump(array_keys($event->getParams())); 33 | }); 34 | 35 | $artistTable->insert(array('name' => 'Foo Fighters')); 36 | 37 | 38 | // USE Non-static Event Manager 39 | 40 | $em = new EM\EventManager; 41 | $artistTable = new TableGateway('artist', $adapter, new EventFeature($em)); 42 | 43 | $em->attach('preDelete', function ($event) { 44 | /** @var $target TableGateway */ 45 | $target = $event->getTarget(); 46 | echo 'This is before Delete of the ' . get_class($target) . ' for table ' . $target->getTable() . PHP_EOL; 47 | echo 'With param names: ' . PHP_EOL; 48 | var_dump(array_keys($event->getParams())); 49 | }); 50 | 51 | $em->attach('postDelete', function ($event) { 52 | /** @var $target TableGateway */ 53 | $target = $event->getTarget(); 54 | echo 'This is after Delete of the ' . get_class($target) . ' for table ' . $target->getTable() . PHP_EOL; 55 | echo 'With params names: ' . PHP_EOL; 56 | var_dump(array_keys($event->getParams())); 57 | }); 58 | 59 | $artistTable->delete(array('name' => 'Foo Fighters')); 60 | 61 | // @todo Currently incomplete as this needs to implement assert_works() -------------------------------------------------------------------------------- /setup/vendor/postgresql.php: -------------------------------------------------------------------------------- 1 | array( 7 | 'CREATE TABLE IF NOT EXISTS "artist" ( 8 | "id" SERIAL PRIMARY KEY, 9 | "name" VARCHAR(255) NOT NULL, 10 | "history" text 11 | );', 12 | 'CREATE TABLE IF NOT EXISTS "album" ( 13 | "id" SERIAL PRIMARY KEY, 14 | "artist_id" INTEGER NOT NULL, 15 | "title" VARCHAR(255) NOT NULL, 16 | "release_date" DATE NOT NULL, 17 | FOREIGN KEY ("artist_id") REFERENCES "artist"("id") ON DELETE CASCADE ON UPDATE CASCADE 18 | );', 19 | 'CREATE TABLE IF NOT EXISTS "genre" ( 20 | "id" SERIAL PRIMARY KEY, 21 | "parent_id" INTEGER DEFAULT NULL, 22 | "name" VARCHAR(255) NOT NULL, 23 | UNIQUE ("name"), 24 | FOREIGN KEY ("parent_id") REFERENCES "genre" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION 25 | );', 26 | 'CREATE TABLE IF NOT EXISTS "artist_genre" ( 27 | "artist_id" INTEGER NOT NULL, 28 | "genre_id" INTEGER NOT NULL, 29 | "added_on" DATE NOT NULL, 30 | PRIMARY KEY ("artist_id","genre_id"), 31 | FOREIGN KEY ("artist_id") REFERENCES "artist" ("id") ON DELETE CASCADE ON UPDATE CASCADE, 32 | FOREIGN KEY ("genre_id") REFERENCES "genre" ("id") ON DELETE CASCADE ON UPDATE CASCADE 33 | );', 34 | 'CREATE TABLE IF NOT EXISTS "track" ( 35 | "id" SERIAL PRIMARY KEY, 36 | "artist_id" INTEGER DEFAULT NULL, 37 | "album_id" INTEGER DEFAULT NULL, 38 | "number" INTEGER DEFAULT NULL, 39 | "title" VARCHAR(255) NOT NULL, 40 | "length" INTEGER NOT NULL, 41 | FOREIGN KEY ("artist_id") REFERENCES "artist" ("id") ON DELETE CASCADE ON UPDATE CASCADE, 42 | FOREIGN KEY ("album_id") REFERENCES "album" ("id") ON DELETE CASCADE ON UPDATE CASCADE 43 | );' 44 | ), 45 | 'schema_down' => array( 46 | 'DROP TABLE IF EXISTS "track"', 47 | 'DROP TABLE IF EXISTS "artist_genre"', 48 | 'DROP TABLE IF EXISTS "genre"', 49 | 'DROP TABLE IF EXISTS "album"', 50 | 'DROP TABLE IF EXISTS "artist"' 51 | ), 52 | 'data_down' => array( 53 | 'DELETE FROM "track"', 54 | 'DELETE FROM "artist_genre"', 55 | 'DELETE FROM "genre"', 56 | 'DELETE FROM "album"', 57 | 'DELETE FROM "artist"', 58 | ), 59 | 60 | )); 61 | 62 | $data['data_up'] = array( 63 | 'artist' => $data['data_up']['artist'], 64 | "SELECT setval('artist_id_seq', 6)", 65 | 'album' => $data['data_up']['album'], 66 | "SELECT setval('album_id_seq', 25)", 67 | 'genre' => $data['data_up']['genre'], 68 | "SELECT setval('genre_id_seq', 4)", 69 | 'artist_genre' => $data['data_up']['artist_genre'], 70 | 'track' => $data['data_up']['track'], 71 | "SELECT setval('track_id_seq', 1)", 72 | ); 73 | 74 | return $data; -------------------------------------------------------------------------------- /includes/functions.php: -------------------------------------------------------------------------------- 1 | getPlatform(); 28 | $platformName = $platform->getName(); 29 | $vendorData = include __DIR__ . '/../setup/vendor/' . str_replace(' ', '-', strtolower($platformName)) . '.php'; 30 | 31 | try { 32 | foreach ($vendorData['data_down'] as $downSql) { 33 | $adapter->query( 34 | $downSql, 35 | $adapter::QUERY_MODE_EXECUTE 36 | ); 37 | } 38 | 39 | foreach ($vendorData['data_up'] as $tableName => $tableData) { 40 | 41 | if ($tableData == null) { 42 | continue; 43 | } 44 | 45 | if (is_int($tableName) && is_string($tableData)) { 46 | $adapter->query( 47 | $tableData, 48 | $adapter::QUERY_MODE_EXECUTE 49 | ); 50 | continue; 51 | } 52 | 53 | foreach ($tableData as $rowName => $rowData) { 54 | 55 | $keys = array_keys($rowData); 56 | $values = array_values($rowData); 57 | array_walk( 58 | $keys, 59 | function (&$key) use ($platform) { 60 | $key = $platform->quoteIdentifier($key); 61 | } 62 | ); 63 | array_walk( 64 | $values, 65 | function (&$value) use ($platform) { 66 | switch (gettype($value)) { 67 | case 'NULL': 68 | $value = 'NULL'; 69 | break; 70 | case 'string': 71 | $value = $platform->quoteValue($value); 72 | break; 73 | } 74 | } 75 | ); 76 | 77 | $insertSql = 'INSERT INTO ' . $platform->quoteIdentifier($tableName) 78 | . ' (' . implode(', ', $keys) . ') ' 79 | . ' VALUES (' . 80 | implode(', ', 81 | $values 82 | ) 83 | . ')'; 84 | 85 | $adapter->query( 86 | $insertSql, 87 | $adapter::QUERY_MODE_EXECUTE 88 | ); 89 | } 90 | } 91 | } catch (\Exception $e) { 92 | echo $e->getMessage(); 93 | var_dump($e); 94 | exit(1); 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /setup/vendor/mysql.php: -------------------------------------------------------------------------------- 1 | array( 9 | "CREATE TABLE IF NOT EXISTS `album` ( 10 | `id` int(11) NOT NULL AUTO_INCREMENT, 11 | `artist_id` int(11) NOT NULL, 12 | `title` varchar(255) NOT NULL, 13 | `release_date` date NOT NULL, 14 | PRIMARY KEY (`id`), 15 | KEY `artist_id` (`artist_id`) 16 | ) ENGINE=$table_type DEFAULT CHARSET=utf8;", 17 | "CREATE TABLE IF NOT EXISTS `artist` ( 18 | `id` int(11) NOT NULL AUTO_INCREMENT, 19 | `name` varchar(255) NOT NULL, 20 | `history` text, 21 | PRIMARY KEY (`id`) 22 | ) ENGINE=$table_type DEFAULT CHARSET=utf8;", 23 | "CREATE TABLE IF NOT EXISTS `artist_genre` ( 24 | `artist_id` int(11) NOT NULL, 25 | `genre_id` int(11) NOT NULL, 26 | `added_on` date NOT NULL, 27 | PRIMARY KEY (`artist_id`,`genre_id`), 28 | KEY `genre_id` (`genre_id`) 29 | ) ENGINE=$table_type DEFAULT CHARSET=utf8;", 30 | "CREATE TABLE IF NOT EXISTS `artist_genre` ( 31 | `artist_id` int(11) NOT NULL, 32 | `genre_id` int(11) NOT NULL, 33 | `added_on` date NOT NULL, 34 | PRIMARY KEY (`artist_id`,`genre_id`), 35 | KEY `genre_id` (`genre_id`) 36 | ) ENGINE=$table_type DEFAULT CHARSET=utf8;", 37 | "CREATE TABLE IF NOT EXISTS `genre` ( 38 | `id` int(11) NOT NULL AUTO_INCREMENT, 39 | `parent_id` int(11) DEFAULT NULL, 40 | `name` varchar(255) NOT NULL, 41 | PRIMARY KEY (`id`), 42 | UNIQUE KEY `name` (`name`), 43 | KEY `parent_id` (`parent_id`) 44 | ) ENGINE=$table_type DEFAULT CHARSET=utf8;", 45 | "CREATE TABLE IF NOT EXISTS `track` ( 46 | `id` int(11) NOT NULL AUTO_INCREMENT, 47 | `artist_id` int(11) DEFAULT NULL, 48 | `album_id` int(11) DEFAULT NULL, 49 | `number` int(11) DEFAULT NULL, 50 | `title` varchar(255) NOT NULL, 51 | `length` int(11) NOT NULL, 52 | PRIMARY KEY (`id`), 53 | KEY `artist_id` (`artist_id`), 54 | KEY `album_id` (`album_id`) 55 | ) ENGINE=$table_type DEFAULT CHARSET=utf8;", 56 | ), 57 | 'schema_down' => array( 58 | 'DROP TABLE IF EXISTS `artist_genre`;', 59 | 'DROP TABLE IF EXISTS `genre`;', 60 | 'DROP TABLE IF EXISTS `track`;', 61 | 'DROP TABLE IF EXISTS `album`;', 62 | 'DROP TABLE IF EXISTS `artist`;' 63 | ), 64 | 'data_down' => array( 65 | 'DELETE FROM `artist_genre`', 66 | 'DELETE FROM `album`', 67 | 'DELETE FROM `artist`', 68 | 'DELETE FROM `genre`', 69 | 'DELETE FROM `track`', 70 | 'ALTER TABLE `artist_genre` AUTO_INCREMENT = 1', 71 | 'ALTER TABLE `album` AUTO_INCREMENT = 1', 72 | 'ALTER TABLE `artist` AUTO_INCREMENT = 1', 73 | 'ALTER TABLE `genre` AUTO_INCREMENT = 1', 74 | 'ALTER TABLE `track` AUTO_INCREMENT = 1', 75 | ), 76 | )); 77 | 78 | if ($table_type == 'InnoDB') { 79 | 80 | $data = array_merge_recursive($data, array( 81 | 'schema_up' => array( 82 | 'ALTER TABLE `album` 83 | ADD CONSTRAINT `fk_album_artist` FOREIGN KEY (`artist_id`) REFERENCES `artist` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;', 84 | 'ALTER TABLE `artist_genre` 85 | ADD CONSTRAINT `fk_artist_genre_artist` FOREIGN KEY (`artist_id`) REFERENCES `artist` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, 86 | ADD CONSTRAINT `fk_artist_genre_genre` FOREIGN KEY (`genre_id`) REFERENCES `genre` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;', 87 | 'ALTER TABLE `genre` 88 | ADD CONSTRAINT `fk_genre_genre` FOREIGN KEY (`parent_id`) REFERENCES `genre` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;', 89 | 'ALTER TABLE `track` 90 | ADD CONSTRAINT `fk_track_artist` FOREIGN KEY (`artist_id`) REFERENCES `artist` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, 91 | ADD CONSTRAINT `fk_track_album` FOREIGN KEY (`album_id`) REFERENCES `album` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;', 92 | ) 93 | )); 94 | 95 | } 96 | return $data; -------------------------------------------------------------------------------- /setup/vendor/sqlserver.php: -------------------------------------------------------------------------------- 1 | array( 9 | 'CREATE TABLE [album] ( 10 | [id] INTEGER PRIMARY KEY IDENTITY, 11 | [artist_id] INTEGER NOT NULL, 12 | [title] varchar(255) NOT NULL, 13 | [release_date] date NOT NULL 14 | );', 15 | 'CREATE TABLE [artist] ( 16 | [id] INTEGER PRIMARY KEY IDENTITY, 17 | [name] varchar(255) NOT NULL, 18 | [history] text 19 | );', 20 | 'CREATE TABLE [genre] ( 21 | [id] INTEGER PRIMARY KEY IDENTITY, 22 | [parent_id] INTEGER DEFAULT NULL, 23 | [name] varchar(255) NOT NULL, 24 | UNIQUE ([name]) 25 | );', 26 | 'CREATE TABLE [artist_genre] ( 27 | [artist_id] INTEGER NOT NULL, 28 | [genre_id] INTEGER NOT NULL, 29 | [added_on] date NOT NULL, 30 | PRIMARY KEY ([artist_id],[genre_id]) 31 | );', 32 | 'CREATE TABLE [track] ( 33 | [id] INTEGER PRIMARY KEY IDENTITY, 34 | [artist_id] INTEGER DEFAULT NULL, 35 | [album_id] INTEGER DEFAULT NULL, 36 | [number] INTEGER DEFAULT NULL, 37 | [title] varchar(255) NOT NULL, 38 | [length] INTEGER NOT NULL 39 | );', 40 | 'ALTER TABLE [album] 41 | ADD CONSTRAINT [fk_album_artist] FOREIGN KEY ([artist_id]) REFERENCES [artist] ([id]) ON DELETE CASCADE ON UPDATE CASCADE', 42 | 'ALTER TABLE [artist_genre] 43 | ADD CONSTRAINT [fk_artist_genre_artist] FOREIGN KEY ([artist_id]) REFERENCES [artist] ([id]) ON DELETE CASCADE ON UPDATE CASCADE', 44 | 'ALTER TABLE [artist_genre] 45 | ADD CONSTRAINT [fk_artist_genre_genre] FOREIGN KEY ([genre_id]) REFERENCES [genre] ([id]) ON DELETE CASCADE ON UPDATE CASCADE', 46 | 'ALTER TABLE [genre] 47 | ADD CONSTRAINT [fk_genre_genre] FOREIGN KEY ([parent_id]) REFERENCES [genre] ([id]) ON DELETE NO ACTION ON UPDATE NO ACTION', 48 | 'ALTER TABLE [track] 49 | ADD CONSTRAINT [fk_track_artist] FOREIGN KEY ([artist_id]) REFERENCES [artist] ([id]) ON DELETE NO ACTION ON UPDATE NO ACTION', 50 | 'ALTER TABLE [track] 51 | ADD CONSTRAINT [fk_track_album] FOREIGN KEY ([album_id]) REFERENCES [album] ([id]) ON DELETE NO ACTION ON UPDATE NO ACTION', 52 | ), 53 | 'schema_down' => array( 54 | 'IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.CONSTRAINT_TABLE_USAGE WHERE TABLE_NAME = \'album\' AND [CONSTRAINT_NAME] = \'fk_album_artist\') 55 | ALTER TABLE [album] DROP CONSTRAINT [fk_album_artist]', 56 | 57 | 'IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.CONSTRAINT_TABLE_USAGE WHERE TABLE_NAME = \'artist_genre\' AND [CONSTRAINT_NAME] = \'fk_artist_genre_artist\') 58 | ALTER TABLE [artist_genre] DROP CONSTRAINT [fk_artist_genre_artist]', 59 | 60 | 'IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.CONSTRAINT_TABLE_USAGE WHERE TABLE_NAME = \'artist_genre\' AND [CONSTRAINT_NAME] = \'fk_artist_genre_genre\') 61 | ALTER TABLE [artist_genre] DROP CONSTRAINT [fk_artist_genre_genre]', 62 | 63 | 'IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.CONSTRAINT_TABLE_USAGE WHERE TABLE_NAME = \'genre\' AND [CONSTRAINT_NAME] = \'fk_genre_genre\') 64 | ALTER TABLE [genre] DROP CONSTRAINT [fk_genre_genre]', 65 | 66 | 'IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.CONSTRAINT_TABLE_USAGE WHERE TABLE_NAME = \'track\' AND [CONSTRAINT_NAME] = \'fk_track_artist\') 67 | ALTER TABLE [track] DROP CONSTRAINT [fk_track_artist]', 68 | 69 | 'IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.CONSTRAINT_TABLE_USAGE WHERE TABLE_NAME = \'track\' AND [CONSTRAINT_NAME] = \'fk_track_album\') 70 | ALTER TABLE [track] DROP CONSTRAINT [fk_track_album]', 71 | 72 | 'IF OBJECT_ID(\'album\') IS NOT NULL DROP TABLE [album]', 73 | 'IF OBJECT_ID(\'artist\') IS NOT NULL DROP TABLE [artist]', 74 | 'IF OBJECT_ID(\'genre\') IS NOT NULL DROP TABLE [genre]', 75 | 'IF OBJECT_ID(\'artist_genre\') IS NOT NULL DROP TABLE [artist_genre]', 76 | 'IF OBJECT_ID(\'track\') IS NOT NULL DROP TABLE [track]' 77 | ), 78 | 'data_down' => array( 79 | 'DELETE FROM [album]', 80 | 'DBCC CHECKIDENT(album, RESEED, 1)', 81 | 'DELETE FROM [artist]', 82 | 'DBCC CHECKIDENT(artist, RESEED, 1)', 83 | 'DELETE FROM [artist_genre]', 84 | 'DELETE FROM [genre]', 85 | 'DBCC CHECKIDENT(genre, RESEED, 1)', 86 | 'DELETE FROM [track]', 87 | 'DBCC CHECKIDENT(track, RESEED, 1)', 88 | ) 89 | )); 90 | 91 | $data['data_up'] = array( 92 | 'SET IDENTITY_INSERT [artist] ON', 93 | 'artist' => $data['data_up']['artist'], 94 | 'SET IDENTITY_INSERT [artist] OFF', 95 | 'SET IDENTITY_INSERT [album] ON', 96 | 'album' => $data['data_up']['album'], 97 | 'SET IDENTITY_INSERT [album] OFF', 98 | 'SET IDENTITY_INSERT [genre] ON', 99 | 'genre' => $data['data_up']['genre'], 100 | 'SET IDENTITY_INSERT [genre] OFF', 101 | 'artist_genre' => $data['data_up']['artist_genre'], 102 | 'track' => $data['data_up']['track'], 103 | ); 104 | 105 | 106 | return $data; -------------------------------------------------------------------------------- /setup/vendor/ibm-db2.php: -------------------------------------------------------------------------------- 1 | array( 7 | 'CREATE TABLE "artist" ( 8 | "id" INTEGER PRIMARY KEY NOT NULL, 9 | "name" VARCHAR(255) NOT NULL, 10 | "history" CLOB 11 | )', 12 | 'CREATE TABLE "album" ( 13 | "id" INTEGER PRIMARY KEY NOT NULL, 14 | "artist_id" INTEGER NOT NULL, 15 | "title" VARCHAR(255) NOT NULL, 16 | "release_date" DATE NOT NULL, 17 | CONSTRAINT "album_artist_fk" FOREIGN KEY ("artist_id") REFERENCES "artist" ("id") 18 | )', 19 | 'CREATE TABLE "genre" ( 20 | "id" INTEGER PRIMARY KEY NOT NULL, 21 | "parent_id" INTEGER DEFAULT NULL, 22 | "name" VARCHAR(255) NOT NULL, 23 | UNIQUE ("name"), 24 | CONSTRAINT "genre_genre_fk" FOREIGN KEY ("parent_id") REFERENCES "genre" ("id") 25 | )', 26 | 'CREATE TABLE "artist_genre" ( 27 | "artist_id" INTEGER NOT NULL, 28 | "genre_id" INTEGER NOT NULL, 29 | "added_on" DATE NOT NULL, 30 | PRIMARY KEY ("artist_id","genre_id"), 31 | CONSTRAINT "artist_genre_artist_fk" FOREIGN KEY ("artist_id") REFERENCES "artist" ("id"), 32 | CONSTRAINT "artist_genre_genre_fk" FOREIGN KEY ("genre_id") REFERENCES "genre" ("id") 33 | )', 34 | 'CREATE TABLE "track" ( 35 | "id" INTEGER PRIMARY KEY NOT NULL, 36 | "artist_id" INTEGER DEFAULT NULL, 37 | "album_id" INTEGER DEFAULT NULL, 38 | "number" INTEGER DEFAULT NULL, 39 | "title" VARCHAR(255) NOT NULL, 40 | "length" INTEGER NOT NULL, 41 | CONSTRAINT "track_artist_fk" FOREIGN KEY ("artist_id") REFERENCES "artist" ("id"), 42 | CONSTRAINT "track_album_fk" FOREIGN KEY ("album_id") REFERENCES "album" ("id") 43 | )', 44 | // 'CREATE SEQUENCE "artist_id_seq" START WITH 1 INCREMENT BY 1 NOMAXVALUE', 45 | // 'CREATE TRIGGER "artist_autoincrement_trig"' . "\n" 46 | // . 'BEFORE INSERT ON "artist"' . "\n" 47 | // . 'FOR EACH ROW WHEN (NEW."id" IS NULL)' . "\n" 48 | // . 'BEGIN SELECT "artist_id_seq".NEXTVAL INTO :NEW."id" FROM DUAL;' . "\n" 49 | // . 'END;', 50 | // 'CREATE SEQUENCE "album_id_seq" START WITH 1 INCREMENT BY 1 NOMAXVALUE', 51 | // 'CREATE TRIGGER "album_autoincrement_trig"' . "\n" 52 | // . 'BEFORE INSERT ON "album"' . "\n" 53 | // . 'FOR EACH ROW WHEN (NEW."id" IS NULL)' . "\n" 54 | // . 'BEGIN SELECT "album_id_seq".NEXTVAL INTO :NEW."id" FROM DUAL;' . "\n" 55 | // . 'END;', 56 | // 'CREATE SEQUENCE "genre_id_seq" START WITH 1 INCREMENT BY 1 NOMAXVALUE', 57 | // 'CREATE TRIGGER "genre_autoincrement_trig"' . "\n" 58 | // . 'BEFORE INSERT ON "genre"' . "\n" 59 | // . 'FOR EACH ROW WHEN (NEW."id" IS NULL)' . "\n" 60 | // . 'BEGIN SELECT "genre_id_seq".NEXTVAL INTO :NEW."id" FROM DUAL;' . "\n" 61 | // . 'END;', 62 | // 'CREATE SEQUENCE "track_id_seq" START WITH 1 INCREMENT BY 1 NOMAXVALUE', 63 | // 'CREATE TRIGGER "track_autoincrement_trig"' . "\n" 64 | // . 'BEFORE INSERT ON "track"' . "\n" 65 | // . 'FOR EACH ROW WHEN (NEW."id" IS NULL)' . "\n" 66 | // . 'BEGIN SELECT "track_id_seq".NEXTVAL INTO :NEW."id" FROM DUAL;' . "\n" 67 | // . 'END;', 68 | // 'CREATE PROCEDURE "reset_sequence"( "p_seq_name" IN VARCHAR2)' . "\n" 69 | // . 'IS "l_val" NUMBER;' . "\n" 70 | // . 'BEGIN' . "\n" 71 | // . 'EXECUTE IMMEDIATE \'SELECT "\' || "p_seq_name" || \'".NEXTVAL FROM DUAL\' INTO "l_val";' . "\n" 72 | // . 'EXECUTE IMMEDIATE \'ALTER SEQUENCE "\' || "p_seq_name" || \'" INCREMENT BY -\' || "l_val" || \' MINVALUE 0\';' . "\n" 73 | // . 'EXECUTE IMMEDIATE \'SELECT "\' || "p_seq_name" || \'".NEXTVAL FROM DUAL \' INTO "l_val";' . "\n" 74 | // . 'EXECUTE IMMEDIATE \'ALTER SEQUENCE "\' || "p_seq_name" || \'" INCREMENT BY 1 MINVALUE 0\';' . "\n" 75 | // . 'END;', 76 | ), 77 | 'schema_down' => array( 78 | // 79 | 'DROP TABLE "track"', 80 | 'DROP TABLE "artist_genre"', 81 | 'DROP TABLE "genre"', 82 | 'DROP TABLE "album"', 83 | 'DROP TABLE "artist"' 84 | 85 | 86 | // 'BEGIN EXECUTE IMMEDIATE \'DROP TABLE "track"\'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN RAISE; END IF; END;', 87 | // 'BEGIN EXECUTE IMMEDIATE \'DROP TABLE "artist_genre"\'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN RAISE; END IF; END;', 88 | // 'BEGIN EXECUTE IMMEDIATE \'DROP TABLE "genre"\'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN RAISE; END IF; END;', 89 | // 'BEGIN EXECUTE IMMEDIATE \'DROP TABLE "album"\'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN RAISE; END IF; END;', 90 | // 'BEGIN EXECUTE IMMEDIATE \'DROP TABLE "artist"\'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN RAISE; END IF; END;', 91 | // 'BEGIN EXECUTE IMMEDIATE \'DROP SEQUENCE "artist_id_seq"\'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -2289 THEN RAISE; END IF; END;', 92 | // 'BEGIN EXECUTE IMMEDIATE \'DROP TRIGGER "artist_autoincrement_trig"\'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -4080 THEN RAISE; END IF; END;', 93 | // 'BEGIN EXECUTE IMMEDIATE \'DROP SEQUENCE "album_id_seq"\'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -2289 THEN RAISE; END IF; END;', 94 | // 'BEGIN EXECUTE IMMEDIATE \'DROP TRIGGER "album_autoincrement_trig"\'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -4080 THEN RAISE; END IF; END;', 95 | // 'BEGIN EXECUTE IMMEDIATE \'DROP SEQUENCE "genre_id_seq"\'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -2289 THEN RAISE; END IF; END;', 96 | // 'BEGIN EXECUTE IMMEDIATE \'DROP TRIGGER "genre_autoincrement_trig"\'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -4080 THEN RAISE; END IF; END;', 97 | // 'BEGIN EXECUTE IMMEDIATE \'DROP SEQUENCE "track_id_seq"\'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -2289 THEN RAISE; END IF; END;', 98 | // 'BEGIN EXECUTE IMMEDIATE \'DROP TRIGGER "track_autoincrement_trig"\'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -4080 THEN RAISE; END IF; END;', 99 | // 'BEGIN EXECUTE IMMEDIATE \'DROP PROCEDURE "reset_sequence"\'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -4043 THEN RAISE; END IF; END;', 100 | ), 101 | 'data_down' => array( 102 | 'DELETE FROM "track"', 103 | 'DELETE FROM "artist_genre"', 104 | 'DELETE FROM "genre"', 105 | 'DELETE FROM "album"', 106 | 'DELETE FROM "artist"', 107 | // 'BEGIN EXECUTE IMMEDIATE \'EXECUTE "reset_sequence" (\\\'artist_id_seq\\\')\'; END;' 108 | ), 109 | 110 | )); 111 | 112 | //foreach ($data['data_up'] as $tName => $tData) { 113 | // foreach ($tData as $tRowIndex => $tRow) { 114 | // foreach ($tRow as $cName => $cValue) { 115 | // if (strpos($cName, '_date') !== false || strpos($cName, '_on') !== false) { 116 | // $data['data_up'][$tName][$tRowIndex][$cName] = date('d-M-y', strtotime($cValue)); 117 | // } 118 | // } 119 | // } 120 | //} 121 | 122 | return $data; 123 | -------------------------------------------------------------------------------- /setup/vendor/common.php: -------------------------------------------------------------------------------- 1 | array( 5 | 'artist' => array( 6 | array( 7 | 'id' => 1, 8 | 'name' => 'Kevin Schroeder', 9 | 'history' => null, 10 | ), 11 | array( 12 | 'id' => 2, 13 | 'name' => 'Linkin Park', 14 | 'history' => null, 15 | ), 16 | array( 17 | 'id' => 3, 18 | 'name' => 'Lady Gaga', 19 | 'history' => null, 20 | ), 21 | array( 22 | 'id' => 4, 23 | 'name' => 'Britney Spears', 24 | 'history' => null, 25 | ), 26 | array( 27 | 'id' => 5, 28 | 'name' => 'ABBA', 29 | 'history' => null, 30 | ), 31 | ), 32 | 'album' => array( 33 | array( 34 | 'id' => 1, 35 | 'artist_id' => 1, 36 | 'title' => 'Coronal Loop Safari', 37 | 'release_date' => '2010-10-1' 38 | ), 39 | array( 40 | 'id' => 2, 41 | 'artist_id' => 1, 42 | 'title' => 'Loudness Wars', 43 | 'release_date' => '2012-05-01' 44 | ), 45 | array( 46 | 'id' => 3, 47 | 'artist_id' => 2, 48 | 'title' => 'Hybrid Theory', 49 | 'release_date' => '2000-05-01' 50 | ), 51 | array( 52 | 'id' => 4, 53 | 'artist_id' => 2, 54 | 'title' => 'Meteora', 55 | 'release_date' => '2003-02-15' 56 | ), 57 | array( 58 | 'id' => 5, 59 | 'artist_id' => 2, 60 | 'title' => 'Minutes to Midnight', 61 | 'release_date' => '2007-07-21' 62 | ), 63 | array( 64 | 'id' => 6, 65 | 'artist_id' => 2, 66 | 'title' => 'A Thousand Suns', 67 | 'release_date' => '2010-05-01' 68 | ), 69 | array( 70 | 'id' => 7, 71 | 'artist_id' => 3, 72 | 'title' => 'The Fame', 73 | 'release_date' => '2008-05-01' 74 | ), 75 | array( 76 | 'id' => 8, 77 | 'artist_id' => 3, 78 | 'title' => 'The Fame Monster', 79 | 'release_date' => '2009-05-01' 80 | ), 81 | array( 82 | 'id' => 9, 83 | 'artist_id' => 3, 84 | 'title' => 'Born This Way', 85 | 'release_date' => '2011-10-10' 86 | ), 87 | array( 88 | 'id' => 10, 89 | 'artist_id' => 4, 90 | 'title' => '...Baby One More Time', 91 | 'release_date' => '1999-2-14' 92 | ), 93 | array( 94 | 'id' => 11, 95 | 'artist_id' => 4, 96 | 'title' => 'Oops!... I Did It Again', 97 | 'release_date' => '2000-10-10' 98 | ), 99 | array( 100 | 'id' => 12, 101 | 'artist_id' => 4, 102 | 'title' => 'Britney', 103 | 'release_date' => '2001-04-06' 104 | ), 105 | array( 106 | 'id' => 13, 107 | 'artist_id' => 4, 108 | 'title' => 'In the Zone', 109 | 'release_date' => '2011-10-10' 110 | ), 111 | array( 112 | 'id' => 14, 113 | 'artist_id' => 4, 114 | 'title' => 'Blackout', 115 | 'release_date' => '2007-10-10' 116 | ), 117 | array( 118 | 'id' => 15, 119 | 'artist_id' => 4, 120 | 'title' => 'Circus', 121 | 'release_date' => '2008-11-23' 122 | ), 123 | array( 124 | 'id' => 16, 125 | 'artist_id' => 4, 126 | 'title' => 'Femme Fatale', 127 | 'release_date' => '2011-10-10' 128 | ), 129 | array( 130 | 'id' => 17, 131 | 'artist_id' => 5, 132 | 'title' => 'Ring Ring', 133 | 'release_date' => '1973-10-10' 134 | ), 135 | array( 136 | 'id' => 18, 137 | 'artist_id' => 5, 138 | 'title' => 'Waterloo', 139 | 'release_date' => '1974-10-10' 140 | ), 141 | array( 142 | 'id' => 19, 143 | 'artist_id' => 5, 144 | 'title' => 'ABBA', 145 | 'release_date' => '1975-10-10' 146 | ), 147 | array( 148 | 'id' => 20, 149 | 'artist_id' => 5, 150 | 'title' => 'Arrival', 151 | 'release_date' => '1976-10-10' 152 | ), 153 | array( 154 | 'id' => 21, 155 | 'artist_id' => 5, 156 | 'title' => 'ABBA: The Album', 157 | 'release_date' => '1977-10-10' 158 | ), 159 | array( 160 | 'id' => 22, 161 | 'artist_id' => 5, 162 | 'title' => 'Voulez-Vous', 163 | 'release_date' => '1979-10-10' 164 | ), 165 | array( 166 | 'id' => 23, 167 | 'artist_id' => 5, 168 | 'title' => 'Super Trouper', 169 | 'release_date' => '1980-10-10' 170 | ), 171 | array( 172 | 'id' => 24, 173 | 'artist_id' => 5, 174 | 'title' => 'The Visitors', 175 | 'release_date' => '1981-10-10' 176 | ), 177 | ), 178 | 'genre' => array( 179 | array( 180 | 'id' => 1, 181 | 'parent_id' => null, 182 | 'name' => 'Rock & Roll/Metal' 183 | ), 184 | array( 185 | 'id' => 2, 186 | 'parent_id' => null, 187 | 'name' => 'Electronic/Dance' 188 | ), 189 | array( 190 | 'id' => 3, 191 | 'parent_id' => null, 192 | 'name' => '70s' 193 | ) 194 | ), 195 | 'artist_genre' => array( 196 | array( 197 | 'artist_id' => 1, 198 | 'genre_id' => 1, 199 | 'added_on' => '2010-11-10' 200 | ), 201 | array( 202 | 'artist_id' => 1, 203 | 'genre_id' => 2, 204 | 'added_on' => '2010-11-10' 205 | ), 206 | array( 207 | 'artist_id' => 2, 208 | 'genre_id' => 1, 209 | 'added_on' => '2010-11-11' 210 | ), 211 | array( 212 | 'artist_id' => 3, 213 | 'genre_id' => 2, 214 | 'added_on' => '2010-11-11' 215 | ), 216 | array( 217 | 'artist_id' => 4, 218 | 'genre_id' => 2, 219 | 'added_on' => '2010-11-11' 220 | ), 221 | array( 222 | 'artist_id' => 5, 223 | 'genre_id' => 3, 224 | 'added_on' => '2010-11-11' 225 | ), 226 | ), 227 | 'track' => array(), 228 | ) 229 | ); 230 | 231 | -------------------------------------------------------------------------------- /setup/vendor/oracle.php: -------------------------------------------------------------------------------- 1 | array( 7 | 'CREATE TABLE "artist" ( 8 | "id" NUMBER PRIMARY KEY, 9 | "name" VARCHAR(255) NOT NULL, 10 | "history" CLOB 11 | )', 12 | 'CREATE TABLE "album" ( 13 | "id" NUMBER PRIMARY KEY, 14 | "artist_id" NUMBER NOT NULL, 15 | "title" VARCHAR(255) NOT NULL, 16 | "release_date" DATE NOT NULL, 17 | CONSTRAINT "album_artist_fk" FOREIGN KEY ("artist_id") REFERENCES "artist" ("id") 18 | )', 19 | 'CREATE TABLE "genre" ( 20 | "id" NUMBER PRIMARY KEY, 21 | "parent_id" NUMBER DEFAULT NULL, 22 | "name" VARCHAR(255) NOT NULL, 23 | UNIQUE ("name"), 24 | CONSTRAINT "genre_genre_fk" FOREIGN KEY ("parent_id") REFERENCES "genre" ("id") 25 | )', 26 | 'CREATE TABLE "artist_genre" ( 27 | "artist_id" NUMBER NOT NULL, 28 | "genre_id" NUMBER NOT NULL, 29 | "added_on" DATE NOT NULL, 30 | PRIMARY KEY ("artist_id","genre_id"), 31 | CONSTRAINT "artist_genre_artist_fk" FOREIGN KEY ("artist_id") REFERENCES "artist" ("id"), 32 | CONSTRAINT "artist_genre_genre_fk" FOREIGN KEY ("genre_id") REFERENCES "genre" ("id") 33 | )', 34 | 'CREATE TABLE "track" ( 35 | "id" NUMBER PRIMARY KEY, 36 | "artist_id" NUMBER DEFAULT NULL, 37 | "album_id" NUMBER DEFAULT NULL, 38 | "number" NUMBER DEFAULT NULL, 39 | "title" VARCHAR(255) NOT NULL, 40 | "length" NUMBER NOT NULL, 41 | CONSTRAINT "track_artist_fk" FOREIGN KEY ("artist_id") REFERENCES "artist" ("id"), 42 | CONSTRAINT "track_album_fk" FOREIGN KEY ("album_id") REFERENCES "album" ("id") 43 | )', 44 | 'CREATE SEQUENCE "artist_id_seq" START WITH 1 INCREMENT BY 1 NOMAXVALUE', 45 | 'CREATE TRIGGER "artist_autoincrement_trig"' . "\n" 46 | . 'BEFORE INSERT ON "artist"' . "\n" 47 | . 'FOR EACH ROW WHEN (NEW."id" IS NULL)' . "\n" 48 | . 'BEGIN SELECT "artist_id_seq".NEXTVAL INTO :NEW."id" FROM DUAL;' . "\n" 49 | . 'END;', 50 | 'CREATE SEQUENCE "album_id_seq" START WITH 1 INCREMENT BY 1 NOMAXVALUE', 51 | 'CREATE TRIGGER "album_autoincrement_trig"' . "\n" 52 | . 'BEFORE INSERT ON "album"' . "\n" 53 | . 'FOR EACH ROW WHEN (NEW."id" IS NULL)' . "\n" 54 | . 'BEGIN SELECT "album_id_seq".NEXTVAL INTO :NEW."id" FROM DUAL;' . "\n" 55 | . 'END;', 56 | 'CREATE SEQUENCE "genre_id_seq" START WITH 1 INCREMENT BY 1 NOMAXVALUE', 57 | 'CREATE TRIGGER "genre_autoincrement_trig"' . "\n" 58 | . 'BEFORE INSERT ON "genre"' . "\n" 59 | . 'FOR EACH ROW WHEN (NEW."id" IS NULL)' . "\n" 60 | . 'BEGIN SELECT "genre_id_seq".NEXTVAL INTO :NEW."id" FROM DUAL;' . "\n" 61 | . 'END;', 62 | 'CREATE SEQUENCE "track_id_seq" START WITH 1 INCREMENT BY 1 NOMAXVALUE', 63 | 'CREATE TRIGGER "track_autoincrement_trig"' . "\n" 64 | . 'BEFORE INSERT ON "track"' . "\n" 65 | . 'FOR EACH ROW WHEN (NEW."id" IS NULL)' . "\n" 66 | . 'BEGIN SELECT "track_id_seq".NEXTVAL INTO :NEW."id" FROM DUAL;' . "\n" 67 | . 'END;', 68 | 'CREATE PROCEDURE "reset_sequence"( "p_seq_name" IN VARCHAR2)' . "\n" 69 | . 'IS "l_val" NUMBER;' . "\n" 70 | . 'BEGIN' . "\n" 71 | . 'EXECUTE IMMEDIATE \'SELECT "\' || "p_seq_name" || \'".NEXTVAL FROM DUAL\' INTO "l_val";' . "\n" 72 | . 'EXECUTE IMMEDIATE \'ALTER SEQUENCE "\' || "p_seq_name" || \'" INCREMENT BY -\' || "l_val" || \' MINVALUE 0\';' . "\n" 73 | . 'EXECUTE IMMEDIATE \'SELECT "\' || "p_seq_name" || \'".NEXTVAL FROM DUAL \' INTO "l_val";' . "\n" 74 | . 'EXECUTE IMMEDIATE \'ALTER SEQUENCE "\' || "p_seq_name" || \'" INCREMENT BY 1 MINVALUE 0\';' . "\n" 75 | . 'END;', 76 | ), 77 | 'schema_down' => array( 78 | 'BEGIN EXECUTE IMMEDIATE \'DROP TABLE "track"\'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN RAISE; END IF; END;', 79 | 'BEGIN EXECUTE IMMEDIATE \'DROP TABLE "artist_genre"\'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN RAISE; END IF; END;', 80 | 'BEGIN EXECUTE IMMEDIATE \'DROP TABLE "genre"\'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN RAISE; END IF; END;', 81 | 'BEGIN EXECUTE IMMEDIATE \'DROP TABLE "album"\'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN RAISE; END IF; END;', 82 | 'BEGIN EXECUTE IMMEDIATE \'DROP TABLE "artist"\'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN RAISE; END IF; END;', 83 | 'BEGIN EXECUTE IMMEDIATE \'DROP SEQUENCE "artist_id_seq"\'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -2289 THEN RAISE; END IF; END;', 84 | 'BEGIN EXECUTE IMMEDIATE \'DROP TRIGGER "artist_autoincrement_trig"\'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -4080 THEN RAISE; END IF; END;', 85 | 'BEGIN EXECUTE IMMEDIATE \'DROP SEQUENCE "album_id_seq"\'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -2289 THEN RAISE; END IF; END;', 86 | 'BEGIN EXECUTE IMMEDIATE \'DROP TRIGGER "album_autoincrement_trig"\'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -4080 THEN RAISE; END IF; END;', 87 | 'BEGIN EXECUTE IMMEDIATE \'DROP SEQUENCE "genre_id_seq"\'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -2289 THEN RAISE; END IF; END;', 88 | 'BEGIN EXECUTE IMMEDIATE \'DROP TRIGGER "genre_autoincrement_trig"\'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -4080 THEN RAISE; END IF; END;', 89 | 'BEGIN EXECUTE IMMEDIATE \'DROP SEQUENCE "track_id_seq"\'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -2289 THEN RAISE; END IF; END;', 90 | 'BEGIN EXECUTE IMMEDIATE \'DROP TRIGGER "track_autoincrement_trig"\'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -4080 THEN RAISE; END IF; END;', 91 | 'BEGIN EXECUTE IMMEDIATE \'DROP PROCEDURE "reset_sequence"\'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -4043 THEN RAISE; END IF; END;', 92 | ), 93 | 'data_down' => array( 94 | 'BEGIN EXECUTE IMMEDIATE \'DELETE FROM "track"\'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN RAISE; END IF; END;', 95 | 'BEGIN EXECUTE IMMEDIATE \'DELETE FROM "artist_genre"\'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN RAISE; END IF; END;', 96 | 'BEGIN EXECUTE IMMEDIATE \'DELETE FROM "genre"\'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN RAISE; END IF; END;', 97 | 'BEGIN EXECUTE IMMEDIATE \'DELETE FROM "album"\'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN RAISE; END IF; END;', 98 | 'BEGIN EXECUTE IMMEDIATE \'DELETE FROM "artist"\'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN RAISE; END IF; END;', 99 | 'BEGIN EXECUTE IMMEDIATE \'EXECUTE "reset_sequence" (\\\'artist_id_seq\\\')\'; END;' 100 | ), 101 | 102 | )); 103 | 104 | foreach ($data['data_up'] as $tName => $tData) { 105 | foreach ($tData as $tRowIndex => $tRow) { 106 | foreach ($tRow as $cName => $cValue) { 107 | if (strpos($cName, '_date') !== false || strpos($cName, '_on') !== false) { 108 | $data['data_up'][$tName][$tRowIndex][$cName] = date('d-M-y', strtotime($cValue)); 109 | } 110 | } 111 | } 112 | } 113 | 114 | //$data['data_up'] = array( 115 | // 'artist' => $data['data_up']['artist'], 116 | // "SELECT setval('artist_id_seq', 6)", 117 | // 'album' => $data['data_up']['album'], 118 | // "SELECT setval('album_id_seq', 25)", 119 | // 'genre' => $data['data_up']['genre'], 120 | // "SELECT setval('genre_id_seq', 4)", 121 | // 'artist_genre' => $data['data_up']['artist_genre'], 122 | // 'track' => $data['data_up']['track'], 123 | // "SELECT setval('track_id_seq', 1)", 124 | //); 125 | 126 | return $data; --------------------------------------------------------------------------------