function migrate_example_oracle_install in Migrate 7.2
Same name and namespace in other branches
- 6.2 migrate_example/migrate_example_oracle/migrate_example_oracle.install \migrate_example_oracle_install()
Implements hook_install().
File
- migrate_example/
migrate_example_oracle/ migrate_example_oracle.install, line 11 - Set up the Oracle migration example module.
Code
function migrate_example_oracle_install() {
global $conf;
// Should never fail - we can't get here unless hook_requirements passed, right?
$connection = @oci_connect($conf['oracle_db']['username'], $conf['oracle_db']['password'], $conf['oracle_db']['connection_string'], 'UTF8');
if (!$connection) {
$e = oci_error();
throw new Exception($e['message']);
}
// Create a table to hold test data
$query = "CREATE TABLE ORACLE_CONTENT\n (OID NUMBER NOT NULL,\n TITLE VARCHAR2(255) NOT NULL,\n BODY CLOB NOT NULL,\n MAINIMAGE BLOB NOT NULL,\n CREATED DATE NOT NULL,\n UPDATED DATE NOT NULL,\n CONSTRAINT ORACLE_CONTENT_PK PRIMARY KEY (OID)\n )";
$result = oci_parse($connection, $query);
if (!$result) {
$e = oci_error($connection);
throw new Exception($e['message'] . "\n" . $e['sqltext']);
}
$status = oci_execute($result);
if (!$status) {
$e = oci_error($result);
throw new Exception($e['message'] . "\n" . $e['sqltext']);
}
// Insert a test row or three
$query = "INSERT INTO ORACLE_CONTENT\n (OID, TITLE, BODY, MAINIMAGE, CREATED, UPDATED)\n VALUES(:oid, :title, EMPTY_CLOB(), EMPTY_BLOB(),\n TO_DATE(:created, 'yyyy/mm/dd hh24:mi:ss'),\n TO_DATE(:updated, 'yyyy/mm/dd hh24:mi:ss'))\n RETURNING body, mainimage INTO :body, :mainimage";
$result = oci_parse($connection, $query);
if (!$result) {
$e = oci_error($connection);
throw new Exception($e['message'] . "\n" . $e['sqltext']);
}
$data = migrate_example_oracle_sample_data();
oci_bind_by_name($result, ':oid', $oid, 1, SQLT_INT);
oci_bind_by_name($result, ':title', $title, 255, SQLT_CHR);
$body_clob = oci_new_descriptor($connection, OCI_D_LOB);
$image_blob = oci_new_descriptor($connection, OCI_D_LOB);
oci_bind_by_name($result, ':body', $body_clob, -1, SQLT_CLOB);
oci_bind_by_name($result, ':mainimage', $image_blob, -1, SQLT_BLOB);
oci_bind_by_name($result, ':created', $created, 9, SQLT_CHR);
oci_bind_by_name($result, ':updated', $updated, 9, SQLT_CHR);
foreach ($data as $row) {
extract($row);
$status = oci_execute($result, OCI_DEFAULT);
if (!$status) {
$e = oci_error($result);
throw new Exception($e['message'] . "\n" . $e['sqltext']);
}
$body_clob
->save($body);
$image_blob
->save($mainimage);
}
oci_commit($connection);
}