473,394 Members | 1,507 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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];
}
?>
Oct 31 '08 #1
2 5390
On Fri, 31 Oct 2008 15:40:39 +0100, peter stickney
<pe***@peterstickney.comwrote:
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.
Here's the code:
#!/usr/bin/php
<?php
dl('sqlite3.so');
error_reporting(6143);
Please, use the constants as indicated by the manual: even it they change
(not htat they should, but just in case), your code will mean the same....
if ( !$db = sqlite3_open($db_file)) die("cannot open file");
Hmmmm, i'd use a "if(!($db = sqlite3_open($db_file)))", I'm not really
sure about the precedence, and if I'm not sure, I'd really like to
indicate it to possible other/future coders.
@$subsystem = $project[1].$project[2];
@$Contact = ($bug["Notify_submitter"]=="Y") ?
@'s are a big nono when developing and encountering a major problem.
Allthough they are before the wrong portion of the statement, you did
remove them I assume?
$sql_ticket = "some query"
echo $sql_ticket."\n";

$query = sqlite3_query($db, $sql_ticket);
As SQLite 3 (http://pecl.php.net/package/sqlite3) is a PECL extention,
might I ask why do you need this extnetion instead of the built in sqlite
support?
if ( !$query ) die(sqlite3_error($db));
sqlite3_query_close($query);
sqlite3_close($db);
$ticket_project[$tn]["Project"] = $project[0];
OK, I seldomly use SQLite (alllthough I'd recommend it for more portable
projects), which statement _exactly_ gave you your "library routine called
out of sequence"?

Personally, unless you've got a very good reason, I'd switch to PDO (with
SQLite), and be done with it...

On a side note, what is your PHP & SQLite version?
--
Rik
Nov 1 '08 #2
On Oct 31, 9:55*pm, "Rik Wasmus" <luiheidsgoe...@hotmail.comwrote:
On Fri, 31 Oct 2008 15:40:39 +0100, peter stickney *

<pe...@peterstickney.comwrote:
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.
Here's the code:
#!/usr/bin/php
<?php
dl('sqlite3.so');
error_reporting(6143);

Please, use the constants as indicated by the manual: even it they change*
(not htat they should, but just in case), your code will mean the same.....
* * * * * *if ( !$db = sqlite3_open($db_file)) die("cannot open file");

Hmmmm, i'd use a "if(!($db = sqlite3_open($db_file)))", I'm not really *
sure about the precedence, and if I'm not sure, I'd really like to *
indicate it to possible other/future coders.
* * * * * *@$subsystem = $project[1].$project[2];
* * * * * *@$Contact = ($bug["Notify_submitter"]=="Y") ?

@'s are a big nono when developing and encountering a major problem. *
Allthough they are before the wrong portion of the statement, you did *
remove them I assume?
* * * * * *$sql_ticket = "some query"
* * * * * *echo $sql_ticket."\n";
* * * * * *$query = sqlite3_query($db, $sql_ticket);

As SQLite 3 (http://pecl.php.net/package/sqlite3) is a PECL extention, *
might I ask why do you need this extnetion instead of the built in sqlite*
support?
* * * * * *if ( !$query ) die(sqlite3_error($db));
* * * * * *sqlite3_query_close($query);
* * * * * *sqlite3_close($db);
* * * * * *$ticket_project[$tn]["Project"] = $project[0];

OK, I seldomly use SQLite (alllthough I'd recommend it for more portable *
projects), which statement _exactly_ gave you your "library routine called *
out of sequence"?

Personally, unless you've got a very good reason, I'd switch to PDO (with*
SQLite), and be done with it...

On a side note, what is your PHP & SQLite version?
--
Rik
I am using
php-5.1.6-20
sqlite-3.3.6-2

both from the standard CentOS 5.2 repos.

For some reason, I had it stuck in my head that PDO did not work with
sqlite3. Maybe it was just the sqlite_()s.

I ended up switching to PDO and everything worked just fine. Used
prepared queries for the INSERTs. Worked out well with some escape
character issues and quoting. Some of the text I was INSERTing had ^s
and []s. The proved troublesome using the sqlite3.so lib.

I often use the die() in concert with fopen and other operations I
would like to know about if they dont work. Never had an issue.

The @s are indeed suppressing warnings I was expecting.

I dont usually use sqlite either, but in this case it was a matter of
necessity. The application I am using relies on that as its DB
backend and I had to import some data from an old program.

Thanks for your tip about the PDO.

-peter
Nov 3 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
by: Steven T. Hatton | last post by:
Now that I have a better grasp of the scope and capabilities of the C++ Standard Library, I understand that products such as Qt actually provide much of the same functionality through their own...
19
by: Deniz Bahar | last post by:
Hi, I would like to call one of my functions the exact name as an existing C library function (for example K&R2 exercises asks me to make an atof function). If I don't include the header with...
4
by: 赿 | last post by:
Tell me why the symbol "_" use in the Library? For example, char *_itoa( int value, char *string, int radix ); But We use function "itoa(value,string,radix) "only. I want to know the...
3
by: Giovanni Boschi | last post by:
We have found a memory leak when using a COM library with a C# application. The leak appears only if the C# application is compiled with the /optimize flag. It goes away when the C# application is...
2
by: Kenny M. | last post by:
hi I have a DB which receive tickets in secuence 1,2,3,4,5.... I want to create an routine that can detect if a ticket is missing so I just need to detect if the secuence is broken (1,2,3,5... ...
4
by: Nikolay Petrov | last post by:
I have an class library, which I shared with some of my apps. Some of them are Winfroms apps, others are ASP .NET. How could I check from a method in my library, is it called form an Winforms or...
7
by: Bob Darlington | last post by:
I'm using the following routine to call UpdateDiary() - below: Private Sub Form_BeforeUpdate(Cancel As Integer) On Error GoTo Form_BeforeUpdate_Error Call UpdateDiary(Me!TenantCounter,...
6
by: RandomElle | last post by:
Hi there I'm hoping someone can help me out with the use of the Eval function. I am using Access2003 under WinXP Pro. I can successfully use the Eval function and get it to call any function with...
1
by: wyse03br | last post by:
Hi all, Using GNU linker ld, I'd like to create a section .rom_code grouping some routines and all its dependencies, including the implicit called ones such as math routines provided by libm.a....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.