split sql script in queries

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

    split sql script in queries

    Hi,

    To simplify this request, we supposed this following sql script:

    "insert into table a values ('me;you','then '); insert into table a
    values ('you;me','so') ;"

    Note the semi-colon ( ; ) in strings for the first field in both
    queries.

    How to split that with preg_split() ?

    Thanks

    Ben

  • gosha bine

    #2
    Re: split sql script in queries

    On 18.04.2007 15:07 Ben wrote:
    Hi,
    >
    To simplify this request, we supposed this following sql script:
    >
    "insert into table a values ('me;you','then '); insert into table a
    values ('you;me','so') ;"
    >
    Note the semi-colon ( ; ) in strings for the first field in both
    queries.
    >
    How to split that with preg_split() ?
    >
    Thanks
    >
    Ben
    >
    hi

    I think the regexp code should be something like

    $sql =
    "insert into table a values ('me;you','then '); insert into table a
    values ('you;me','so') ;"
    ;

    preg_match_all(
    "/('(\\\\.|.)*?'|[^;])+/s",
    $sql,
    $matches);
    $stmts = $matches[0];
    print_r($stmts) ;




    --
    gosha bine

    extended php parser ~ http://code.google.com/p/pihipi
    blok ~ http://www.tagarga.com/blok

    Comment

    Working...