Re: [PHP] Having a bit of regex troubles

2004-01-14 Thread David OBrien
I just ran this on this line...

for ($x=0; $x
to see the ascii values to make sure nothing funky was there and it still 
stopped after the @@ (169)(169)

-Dave

At 12:50 AM 1/15/2004, David OBrien wrote:
Let's say i have a mysqldump type export script I wrote that someone 
screwed up (me) and I quoted every field even the
numeric ones. In this dump I have rows upon rows of this kind of data

INSERT INTO chd VALUES ( '80607fe5-00eb-f5c9-4d38-00ac10050a00' , 
'014d7fcd-00eb-f5c9-4d38-00ac10050a00' ,
 'Kenderick' , '1991-02-10' , 'Male' , '2002-02-28' , '576' , '' , '' , 
'Full-Time' , 'Summer Only' , '©After School©' ,
 '©Child Care Center©©(CCC) Summer Camp©' , '©Non-Smoking©' , '©English©' 
, '' , ''
 , '' , '' , '' , '' , '©CMS - Tuckaseegee©' , '©Transportation 
Provided©' , ''  );

The java programmer used @@ as internal field seperators (can't be changed)

I am reading this dump a line at a time stripping the data into an array 
and then writing back out to a new file
with the proper fields quoted or not quoted depending on the table and the 
db schema
"ccncc" would be "char char num char char" in the switch statement to tell 
the loop which ones to quote
or which ones not to.

ACTUAL SCRIPT AT THE END (kind of large)

In the example row above You see the @@(CCC) value?

Whenever It gets to a line with this combination it stops processing the 
rest of that line and terminates the field at the @@

Dump of the below program for the above row ( I put the *** before and 
after each field to see where it was dieing)

INSERT INTO chd VALUES  (
***80607fe5-00eb-f5c9-4d38-00ac10050a00***
***014d7fcd-00eb-f5c9-4d38-00ac10050a00***
***Kenderick***
***1991-02-10***
***Male***
***2002-02-28***
**
**
***Full-Time***
***Summer Only***
***©After School©***
***©Child Care Center©©***
Then it just skips to the next record when it hits the (CCC). I could just 
use a text editor to replace all the @@( to
something and then write them back out at the end of the script but it's 
really bugging me and I thought a fresh pair
of eyes looking over it would help.

I know I have trims out the wazoo but I just rushed to post this before it 
got real late.

Anyone know of a way I can replace the (CCC) or the @@ using str_replace 
I've tried \'ing it, not slashing just about
every combination
-Dave







SCRIPT

[EMAIL PROTECTED] bin]# cat escape_sql.php
#!/bin/php

  Usage:
   filename

$fields = explode("' , '" , $rest);
foreach ($fields as $field) {
$field = trim($field, "' ");
$field = trim($field, "\' ");
$table = str_replace("INSERT INTO ","", 
$sql );
$table = str_replace("VALUES" , "" , $table);
$table = trim($table);
switch ($table) {
case 'agc':
$schema = 
"";
break;
case 'chd':
$schema = 
"ccnc";
break;
case 'cli':
$schema = 
"cncnncnncncn";
break;
case 'cliactionlog':
$schema = "cc";
break;
case 'cliaddress':
$schema = "nn";
break;
case 'clicensus':
$schema = "c";
break;
case 'clifollow':
$schema = 
"nn";
break;
case 'cligeneral':
$schema = 
"nccc";
break;
case 'cliref':
$schema = "c";
break;
case 'clistats':
$schema = "cccncc";
break;
case 'cnd':
$schema = "";
 

[PHP] Having a bit of regex troubles

2004-01-14 Thread David OBrien
Let's say i have a mysqldump type export script I wrote that someone 
screwed up (me) and I quoted every field even the
numeric ones. In this dump I have rows upon rows of this kind of data

INSERT INTO chd VALUES ( '80607fe5-00eb-f5c9-4d38-00ac10050a00' , 
'014d7fcd-00eb-f5c9-4d38-00ac10050a00' ,
 'Kenderick' , '1991-02-10' , 'Male' , '2002-02-28' , '576' , '' , '' , 
'Full-Time' , 'Summer Only' , '©After School©' ,
 '©Child Care Center©©(CCC) Summer Camp©' , '©Non-Smoking©' , '©English©' 
, '' , ''
 , '' , '' , '' , '' , '©CMS - Tuckaseegee©' , '©Transportation Provided©' 
, ''  );

The java programmer used @@ as internal field seperators (can't be changed)

I am reading this dump a line at a time stripping the data into an array 
and then writing back out to a new file
with the proper fields quoted or not quoted depending on the table and the 
db schema
"ccncc" would be "char char num char char" in the switch statement to tell 
the loop which ones to quote
or which ones not to.

ACTUAL SCRIPT AT THE END (kind of large)

In the example row above You see the @@(CCC) value?

Whenever It gets to a line with this combination it stops processing the 
rest of that line and terminates the field at the @@

Dump of the below program for the above row ( I put the *** before and 
after each field to see where it was dieing)

INSERT INTO chd VALUES  (
***80607fe5-00eb-f5c9-4d38-00ac10050a00***
***014d7fcd-00eb-f5c9-4d38-00ac10050a00***
***Kenderick***
***1991-02-10***
***Male***
***2002-02-28***
**
**
***Full-Time***
***Summer Only***
***©After School©***
***©Child Care Center©©***
Then it just skips to the next record when it hits the (CCC). I could just 
use a text editor to replace all the @@( to
something and then write them back out at the end of the script but it's 
really bugging me and I thought a fresh pair
of eyes looking over it would help.

I know I have trims out the wazoo but I just rushed to post this before it 
got real late.

Anyone know of a way I can replace the (CCC) or the @@ using str_replace 
I've tried \'ing it, not slashing just about
every combination
-Dave







SCRIPT

[EMAIL PROTECTED] bin]# cat escape_sql.php
#!/bin/php

  Usage:
   filename

$fields = explode("' , '" , $rest);
foreach ($fields as $field) {
$field = trim($field, "' ");
$field = trim($field, "\' ");
$table = str_replace("INSERT INTO ","", 
$sql );
$table = str_replace("VALUES" , "" , $table);
$table = trim($table);
switch ($table) {
case 'agc':
$schema = 
"";
break;
case 'chd':
$schema = 
"ccnc";
break;
case 'cli':
$schema = 
"cncnncnncncn";
break;
case 'cliactionlog':
$schema = "cc";
break;
case 'cliaddress':
$schema = "nn";
break;
case 'clicensus':
$schema = "c";
break;
case 'clifollow':
$schema = 
"nn";
break;
case 'cligeneral':
$schema = 
"nccc";
break;
case 'cliref':
$schema = "c";
break;
case 'clistats':
$schema = "cccncc";
break;
case 'cnd':
$schema = "";
break;
case 'com':
$schema = 
"cncncnncnnc";
break;