php_sqlite3 library routine called out of sequence



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($project) {
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,$arr_date[0],$arr_date[1],$arr_date[2]);

return $CVSTracDate;
}

$ddts_bugs_file = "/root/DDTS_export/defects.csv";
$ddts_handle = fopen($ddts_bugs_file, "r");

$headers_bool = FALSE;
while($data = fgetcsv($ddts_handle, 0, ",")) {
if ( !$headers_bool ) {
$headers = $data;
$headers_bool = TRUE;
}
else {
$tn = str_replace("ABCqa0", "", $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($project[0]);
if ( !$db = sqlite3_open($db_file)) die("cannot open file");

@$subsystem = $project[1].$project[2];
@$Contact = ($bug["Notify_submitter"]=="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"]}',
'".ParseDDTSDate($bug["Submitted_on"])."',
'".ParseDDTSDate($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_error($db));

sqlite3_query_close($query);
sqlite3_close($db);
$ticket_project[$tn]["Project"] = $project[0];
}
?>
.



Relevant Pages

  • Re: Confused by mysqli
    ... When I started using MySQL with Perl back in 1998, ... fetch_assocon a query I prepared with bind variables, ... So I had it print out its eval string that it was trying to run. ... PHP will fail to run at all, because bind_result will not have enough ...
    (comp.lang.php)
  • Re: [PHP] PHP & MySQL Problem
    ... [PHP] PHP & MySQL Problem ... > actually there seems to be no problem with your query (besides that you ...
    (php.general)
  • Re: php_sqlite3 library routine called out of sequence
    ... Zend Engine v2.1.0, ... CSV does not go into the same database, I am using PHP to do this. ... I seldomly use SQLite (alllthough I'd recommend it for more portable   ...
    (comp.lang.php)
  • Re: timestamp
    ... PHP newsgroup, and should be discussed in comp.databases.mysql). ... Then click on the Survey link."; ... your SQL syntax; check the manual that corresponds to your MySQL ... Your query fails because a datetime value needs to be in single quotes in the query, ...
    (comp.lang.php)
  • Re: [PHP] Architecture patterns in PHP
    ... 316 Query SHOW TABLES FROM `cake` ... 316 Query DESCRIBE `posts` ... Application and Templating Framework for PHP ... when they cache the results of reverse engineer the object model from ...
    (php.general)