I am running CentOS 5.2, with all current updates
PHP 5.1.6 -
PHP 5.1.6 (cli) (built: Jul 16 2008 19:53:00)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
And I downloaded and installed with no issue php-sqlite3-0.5
I have a sqlite3 DB that I am trying to populate with data from a
CSV. Because of data manipulation and the fact that the data from the
CSV does not go into the same database, I am using PHP to do this. My
code runs for exactly 2 queries, INSERTs the data properly and then
exits with this error:
library routine called out of sequence
Basically I read each line of CSV, determine which DB to open, open
it, form an INSERT query, run the query, close the DB.
This is run off the command line.
Any help is greatly appreciated.
Thanks.
-peter
Here's the code:
#!/usr/bin/php
<?php
ini_set('memory _limit', '512M');
dl('sqlite3.so' );
error_reporting (6143);
function GetDBFile($proj ect) {
switch($project ) {
case "projectA":
return "/usr/local/db/cvstrac/projectA.db";
break;
case "projectB":
return "/usr/local/db/cvstrac/projectB.db";
break;
case "projectC":
return "/usr/local/db/cvstrac/projectC.db";
break;
}
}
function ParseDDTSDate($ DDTSDate) {
// convert mm/dd/yy to unixtimestamp
$arr_date = explode("/", $DDTSDate);
$CVSTracDate = mktime(0,0,0,$a rr_date[0],$arr_date[1],$arr_date[2]);
return $CVSTracDate;
}
$ddts_bugs_file = "/root/DDTS_export/defects.csv";
$ddts_handle = fopen($ddts_bug s_file, "r");
$headers_bool = FALSE;
while($data = fgetcsv($ddts_h andle, 0, ",")) {
if ( !$headers_bool ) {
$headers = $data;
$headers_bool = TRUE;
}
else {
$tn = str_replace("AB Cqa0", "", $data[0]);
foreach ( $data as $key=>$val ) {
$ddts_bug[$tn][$headers[$key]] = $val;
}
}
}
// for each bug, look and see what DB it belongs in, form the query,
run the query.
$x=0;
foreach ( $ddts_bug as $tn=>$bug ) {
$project = preg_split("/-/", $bug["Project"]);
$db_file = GetDBFile($proj ect[0]);
if ( !$db = sqlite3_open($d b_file)) die("cannot open file");
@$subsystem = $project[1].$project[2];
@$Contact = ($bug["Notify_submitt er"]=="Y") ?
$bug["Submitter_mail "] : NULL;
$sql_ticket = "INSERT INTO ticket (tn, type, status, origtime,
changetime, derivedfrom, version, assignedto, severity, priority,
subsystem, owner, title, contact, extra1, extra2, extra3, extra4,
extra5, description, remarks)
VALUES ( {$tn},
'{$bug["Problem"]}',
'{$bug["Status"]}',
'".ParseDDTSDat e($bug["Submitted_ on"])."',
'".ParseDDTSDat e($bug["new_on"])."',
NULL,
NULL,
'{$bug["Engineer"]}',
'{$bug["Severity"]}',
3,
'{$subsystem}',
'{$bug["Submitter_ id"]}',
'{$bug["Headline"]}',
'{$Contact}',
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL);";
echo $sql_ticket."\n ";
$query = sqlite3_query($ db, $sql_ticket);
if ( !$query ) die(sqlite3_err or($db));
sqlite3_query_c lose($query);
sqlite3_close($ db);
$ticket_project[$tn]["Project"] = $project[0];
}
?>
PHP 5.1.6 -
PHP 5.1.6 (cli) (built: Jul 16 2008 19:53:00)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
And I downloaded and installed with no issue php-sqlite3-0.5
I have a sqlite3 DB that I am trying to populate with data from a
CSV. Because of data manipulation and the fact that the data from the
CSV does not go into the same database, I am using PHP to do this. My
code runs for exactly 2 queries, INSERTs the data properly and then
exits with this error:
library routine called out of sequence
Basically I read each line of CSV, determine which DB to open, open
it, form an INSERT query, run the query, close the DB.
This is run off the command line.
Any help is greatly appreciated.
Thanks.
-peter
Here's the code:
#!/usr/bin/php
<?php
ini_set('memory _limit', '512M');
dl('sqlite3.so' );
error_reporting (6143);
function GetDBFile($proj ect) {
switch($project ) {
case "projectA":
return "/usr/local/db/cvstrac/projectA.db";
break;
case "projectB":
return "/usr/local/db/cvstrac/projectB.db";
break;
case "projectC":
return "/usr/local/db/cvstrac/projectC.db";
break;
}
}
function ParseDDTSDate($ DDTSDate) {
// convert mm/dd/yy to unixtimestamp
$arr_date = explode("/", $DDTSDate);
$CVSTracDate = mktime(0,0,0,$a rr_date[0],$arr_date[1],$arr_date[2]);
return $CVSTracDate;
}
$ddts_bugs_file = "/root/DDTS_export/defects.csv";
$ddts_handle = fopen($ddts_bug s_file, "r");
$headers_bool = FALSE;
while($data = fgetcsv($ddts_h andle, 0, ",")) {
if ( !$headers_bool ) {
$headers = $data;
$headers_bool = TRUE;
}
else {
$tn = str_replace("AB Cqa0", "", $data[0]);
foreach ( $data as $key=>$val ) {
$ddts_bug[$tn][$headers[$key]] = $val;
}
}
}
// for each bug, look and see what DB it belongs in, form the query,
run the query.
$x=0;
foreach ( $ddts_bug as $tn=>$bug ) {
$project = preg_split("/-/", $bug["Project"]);
$db_file = GetDBFile($proj ect[0]);
if ( !$db = sqlite3_open($d b_file)) die("cannot open file");
@$subsystem = $project[1].$project[2];
@$Contact = ($bug["Notify_submitt er"]=="Y") ?
$bug["Submitter_mail "] : NULL;
$sql_ticket = "INSERT INTO ticket (tn, type, status, origtime,
changetime, derivedfrom, version, assignedto, severity, priority,
subsystem, owner, title, contact, extra1, extra2, extra3, extra4,
extra5, description, remarks)
VALUES ( {$tn},
'{$bug["Problem"]}',
'{$bug["Status"]}',
'".ParseDDTSDat e($bug["Submitted_ on"])."',
'".ParseDDTSDat e($bug["new_on"])."',
NULL,
NULL,
'{$bug["Engineer"]}',
'{$bug["Severity"]}',
3,
'{$subsystem}',
'{$bug["Submitter_ id"]}',
'{$bug["Headline"]}',
'{$Contact}',
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL);";
echo $sql_ticket."\n ";
$query = sqlite3_query($ db, $sql_ticket);
if ( !$query ) die(sqlite3_err or($db));
sqlite3_query_c lose($query);
sqlite3_close($ db);
$ticket_project[$tn]["Project"] = $project[0];
}
?>
Comment