473,511 Members | 15,715 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5396
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
4913
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
2479
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
2434
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
2527
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
1046
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
1260
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
2413
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
5883
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
1689
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
7251
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7148
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
7367
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
7430
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...
0
5673
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3217
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1581
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.