473,672 Members | 2,497 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($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];
}
?>
Oct 31 '08 #1
2 5403
On Fri, 31 Oct 2008 15:40:39 +0100, peter stickney
<pe***@petersti ckney.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($d b_file)) die("cannot open file");
Hmmmm, i'd use a "if(!($db = sqlite3_open($d b_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_submitt er"]=="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_err or($db));
sqlite3_query_c lose($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.comwro te:
On Fri, 31 Oct 2008 15:40:39 +0100, peter stickney *

<pe...@petersti ckney.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($d b_file)) die("cannot open file");

Hmmmm, i'd use a "if(!($db = sqlite3_open($d b_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_submitt er"]=="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_err or($db));
* * * * * *sqlite3_query_ close($query);
* * * * * *sqlite3_close( $db);
* * * * * *$ticket_projec t[$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
4967
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 libraries. I'm not sure if that's a good thing or not. AFAIK, most of Qt is compatable with the Standard Library. That is, QLT can interoperate with STL, and you can convert back and forth between std::string and Qt::QString, etc. Are there any...
19
2501
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 the declaration for the C library function (stdlib.h in this case) then define/declare my own function with the same name, am I safe? It seems to work on my compiler, but I wonder if this is portable or even acceptable? thx
4
2442
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 specific reason .
3
2539
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 compiled with the /debug flag. The COM library is coded to fire asynchronous events, which are handled by the C# application. It is in the firing and handling of these events that the leak occurs. Why does the optimized application leak while...
2
1055
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 is missing) I want to create a good routine and I can only thing about a for loop with IF THEN inside Any one have an idea?
4
1266
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 ASP .NET? tnx
7
2417
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, "sfTenantDetailsOther") Exit Sub Form_BeforeUpdate_Error: MsgBox "Error " & Err.Number & " (" & Err.Description & ") " _ & "in procedure Form_BeforeUpdate in Line " & Erl & "."
6
5910
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 or without parms. I know that any function that is passed to Eval() must be declared Public. It can be a Sub or Function, as long as it's Public. I even have it where the "function" evaluated by Eval can be in a form (class) module or in a standard...
1
1698
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. Going down in more details, my intention is creating a stand-alone ROM image containing several utility routines (with all its dependencies) that will be used by programs loaded in RAM. The C code is something like:
0
8403
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8930
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8828
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8605
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7446
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4227
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2819
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 we have to send another system
2
2062
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.