php_sqlite3 library routine called out of sequence

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • peter stickney

    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];
    }
    ?>
  • Rik Wasmus

    #2
    Re: php_sqlite3 library routine called out of sequence

    On Fri, 31 Oct 2008 15:40:39 +0100, peter stickney
    <peter@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

    Comment

    • peter stickney

      #3
      Re: php_sqlite3 library routine called out of sequence

      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_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
      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

      Comment

      Working...