Let me deviate a little bit and say how cool SQLite is. It makes handling a database just like string manipulation in PERL!
Anyways, what I wanted to know is that, I would like to log some specific queries to text files having the same filename as that of the table name(s) on which the query is run.
Here is how I can call this :sub dumpResultsToFile { my ( $query ) = @_; # Prepare and execute the query my $sth = $dbh->prepare( $query ); $sth->execute(); # Open the output file open FILE, ">results.txt" or die "Can't open results output file: +$!"; # Dump the formatted results to the file $sth->dump_results( 80, "\n", ", ", \*FILE ); # Close the output file close FILE or die "Error closing result file: $!\n"; }
dumpResultsToFile ( <<" END_SQL" ); SELECT TADA.fileName, TADA.labelName FROM TADA END_SQL
What I effectiively want is, instead of stuff going to "results.txt" ( that is hardcoded above ), it should now go to "TADA.txt".
Had this been a join between tables "HAI" and "LOL", then the resultset should be written to "HAI.LOL.txt"
Is what I am saying even possible using some magic in DBI?
I would rather do without parsing the SQL query for tables, but if there is a widely used and debugged function to grab source table names in a SQL query, that would work for me too!
What I want is just to have a filename that gives some hint as to what query output it holds. Segregating based on table name seems a nice way for now.
In reply to Grabbing source table names from a SQL query by PoorLuzer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |