swooper120 0 #1 November 20, 2003 ...im ready for the lashings... Coming from a Windows Programming background.. I have a .dbm file, that I want to import or convert into a SQL or access database..is this possible? I have searched the net and newsgroups, and cant find any real info. My manifest programs use the dbm file and I am currently writing my own custom app with a SQL background...and if it all possible I would like to import all my customer files into the sql db from the dbm file.. Is there a program or exe, that can do this? or I am dead in the water? Thanks in advance? swooper120 Quote Share this post Link to post Share on other sites
indyz 1 #2 November 20, 2003 Quote ...im ready for the lashings... Coming from a Windows Programming background.. I have a .dbm file, that I want to import or convert into a SQL or access database..is this possible? I have searched the net and newsgroups, and cant find any real info. My manifest programs use the dbm file and I am currently writing my own custom app with a SQL background...and if it all possible I would like to import all my customer files into the sql db from the dbm file.. Is there a program or exe, that can do this? or I am dead in the water? Thanks in advance? swooper120 Sure it's possible. Perl has built in methods for accessing some types of dbm files. If it doesn't work with yours, try the AnyDBM_File module. You will also need the DBI module and a DBD driver for whatever SQL database you are planning on using (on Windows you will probably want ODBC). It probably won't be easy (especially if you want to reorganize the tables at the same time). Learn Perl if you don't already know it, then learn databases in Perl, then roll it all together. If you have questions, try Perlmonks. Edit: Oops, left out DBI the first time around. Quote Share this post Link to post Share on other sites
MikeMcLean 0 #3 November 20, 2003 If this is a one time data dump and import you may be over-engineering trying to create a Pearl application to DBM-Read, translate, and SQL-Write-With-DBI-Interface. Do you have an existing way to export basic text from your DBM application? If so most of the SQL admin tools (for MySQL, Postgres, SQL-Server, etc.) have a import from file option. If you do need more power, the SQL side is pretty straight forward to create code for: #!/bin/perl # Open it $driver = "mysql"; # or whatever (installed and supported) $dsn = "DBI:$driver:database=DB_NAME;host=DNS_NAME_OR_IP;"; $dbh = DBI->connect($dsn, 'username', 'password'); # Use it (inserts) $sth = $dbh->prepare("INSERT INTO `table_name` (f1, f2, f3) VALUES ( ?, ?, ? );"); # replace ?'s with data $sth->bind_param(1, $perl_variable_for_f1); $sth->bind_param(2, $perl_variable_for_f2); $sth->bind_param(3, $perl_variable_for_f3); # execute $rc = $sth->execute(); # use it, update one field in one record $sth = $dbh->prepare("UPDATE `table` SET `f1` = ? WHERE `f2` = ? LIMIT 1;"); $sth->bind_param(1, $f1_new_value); $sth->bind_param(2, $f2_lookup_value); $sth->execute(); # use it, select and read one record $sth = $dbh->prepare("SELECT f1, f2 from table WHERE `f1` = ?;"); $sth->bind_param(1, $lookup_value); $rv = $sth->execute(); if ( $rv == 1) { my ($f1, $f2); @row = $sth->fetchrow_array; ($f1, $f2) = @row; } There are lots of additional options to DBI->connect, and I ignored error checking in the simple examples above. The DBI does support transactions ($dbh->commit() and $dbh->rollback()) if your underlying database supports them. Good Luck!It wouldn't hurt you to think like a fucking serial killer every once in a while - just for the sake of prevention Quote Share this post Link to post Share on other sites
Fast 0 #4 November 20, 2003 If you know perl already this probally wont be that hard. Other than the sites that indyz said you can always look at perldoc which is bassically everything in perl in multiple versions. I guess it comes down to knowing how the dbm stuff is set up, where you want to go with the data, and knowing how to get it from point A to point B. Above example is also pretty much right on.~D Where troubles melt like lemon drops Away above the chimney tops That's where you'll find me. Swooping is taking one last poke at the bear before escaping it's cave - davelepka Quote Share this post Link to post Share on other sites