vbrtrmn has asked for the wisdom of the Perl Monks concerning the following question:
Okay, to start I'm dealing with the most poorly designed database I've ever seen. My goal is to cut certain records out of a 1.4 million record database, based on readability of the word. That part is easy!
Database Sampling:
| ID | WORD | FLAG | LWORD | dc5943 | bears | 0 | bears | mu0286 | best summer tunes | 0 | bestsummertunes | mu0286 | bestsummertunes | 1 | | muz334 | chk chk chk | 0 | chkchkchk | ofn00861 | chuck e cheese.com | 0 | chuckecheesecom | dcz013 | dc restaurants | 0 | dcrestaurants | dcz0013 | dc restaurants | 0 | dcrestaurants | dcz013 | dc resturants | 1 | | dcz0013 | dc resturants | 1 | | dcz013 | dc american dining | 0 | dcamericandining | dcz0003 | elmira wv | 0 | elmirawv | dc0160 | elmira, c. a. | 1 | | tw0056 | elmira, n. y. | 1 |
Okay, I'll just sort based on how the data comes in via the FLAG. Depending on what the last record was I can determine what to do with the current one... or so I thought.
I'm using DBI, binding the column names with $sth->bind_columns(...); and grabbing the rows with while($sth->fetch()) { ... }. The data, which perl outputs isn't in the same order as the database.
Output Sampling (first 10 records):
| ID | WORD | FLAG | LWORD | wq12351y059 | hawkinschemical | 1 | | wq12366y059 | healtheon corp. | 1 | | wq12367y059 | healthgatedata. | 1 | | wq12382y059 | helixtechnology | 1 | | wq12385y059 | helpathome,inc. | 1 | | wq12390y059 | henryschein,inc | 1 | | wq12390y059 | henryscheininc. | 1 | | wq12397y059 | hermanmillerinc | 1 | | wq12404y059 | hffinancialcorp | 1 | | wq12409y059 | hickorytechcorp | 1 |
Is there a way for me to get the data out of the DB as it appears OR will it return this way everytime (it always comes back this way).
Here's my code (exerpt), for reference:
$DSN = 'DBI:ODBC:SearchWords'; $USER= ''; $PASS= 'password'; $DBH = DBI->connect( $DSN, $USER, $USER ) || die "Connect Error: $DBI: +:errstr\n"; my $SQL = "SELECT * FROM [Production Words]"; my $sth = $DBH->prepare($SQL); $sth->execute || die "Could not execute SQL statement ... maybe invali +d?\n$!"; $sth->bind_columns(\$aid,\$wd,\$we,\$df,\$lw,\$sw); while($sth->fetch()) { print "$aid\t$wd\t$we\t$df\t$lw\t$sw\n"; } $DBH->disconnect();
System Info: Win32, Perl 5.8.2 on Cygwin, standard CPAN DBI module.
--
paul
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Database Record Order
by MidLifeXis (Monsignor) on Dec 30, 2003 at 22:13 UTC | |
by vbrtrmn (Pilgrim) on Dec 30, 2003 at 22:29 UTC | |
by jeffa (Bishop) on Dec 30, 2003 at 22:48 UTC | |
by thor (Priest) on Dec 31, 2003 at 00:45 UTC | |
by exussum0 (Vicar) on Dec 31, 2003 at 04:38 UTC | |
|
Re: Database Record Order
by jeffa (Bishop) on Dec 30, 2003 at 22:31 UTC | |
by edan (Curate) on Dec 31, 2003 at 06:48 UTC | |
by thor (Priest) on Dec 31, 2003 at 13:40 UTC | |
by jeffa (Bishop) on Dec 31, 2003 at 15:21 UTC | |
by thor (Priest) on Dec 31, 2003 at 16:01 UTC | |
by vbrtrmn (Pilgrim) on Dec 30, 2003 at 22:34 UTC | |
|
Re: Database Record Order
by edoc (Chaplain) on Dec 30, 2003 at 22:20 UTC | |
by monktim (Friar) on Dec 31, 2003 at 14:12 UTC | |
by mpeppler (Vicar) on Dec 31, 2003 at 22:19 UTC |