Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Quick Import

Quote Reply
Quick Import
Jerry,

Have you made a quick-import tool yet? Just a script that reads the header information and the list of records and reads it in? Once the database is set up, reading in the records becomes a pain.... but a utility to do it is trivial --- if you've done it can you post it, if not, I'll probably have something to post this weekend... I figure it's a dozen lines of code if that..... The only trick is making it flexible by reading a header file as opposed to coding the fields individually.
Quote Reply
Re: Quick Import In reply to
you do mean "Alex".. not "Jerry" right..

i was like.. WHAT?!?! WHAT IS THIS?!?! Smile

anyways.. i don't get what you mean by read the headers in..

jerry
Quote Reply
Re: Quick Import In reply to
No, I meant you.... Wink

You seem to have done everything else...

When importing, you need the first line to be the field names... that's the header. Followed by the lines of data.
Quote Reply
Re: Quick Import In reply to
oh..

so it keeps the same structure?

nope.. i've never hand made a SQL table before.. hehe Smile

but if i felt like it.. i'd look in editor.cgi to look at the Resync code to figure out how to figure out the length's and attributes of a field.. all i could do is probably get a list of fields and add it in to a database.. but not with the exact attributes..

jerry

Quote Reply
Re: Quick Import In reply to
Ah... you are missing the point.

Just an import that will take a file (short example)

ID|name|stuff
1|link1|good stuff1
2|link2|good stuff2
3|link3|good stuff3

And just insert it into the specified table, field for field, not really caring about anything else. basically, a "quick import"

The existing tools are kinda rough, and all this would do is encapsulate one specific process into a silly little utility. But, it keeps the hands off the ugly stuff.
Quote Reply
Re: Quick Import In reply to
oh..

well.. that'd basically be something like this

Code:
open DB, "file.db";
chomp ($fields = <DB> );
@fields = split /\|/, $fields;
@db = <DB>;
close DB;

foreach (@db) {
$i = 0;
@item = split /\|/, $_;
%item = map { $fields[$i++] => $_ } @item;
$insert_name = $insert_value = "";
foreach (@fields) {
$item{$_} or next;
$insert_name .= "$_,";
$insert_value .= $DBH->quote($item{$_}) . ",";
}
$sth = $DBH->prepare ("INSERT INTO NEWTABLE ($insert_name) VALUES ($insert_value)");
$sth->execute();
}

not say it's gonna work with just that code though ;-)

jerry
Quote Reply
Re: Quick Import In reply to
I added Quick Import/Export to the third beta, basically this uses Mysql's SELECT INTO OUTFILE, and LOAD DATA INFILE. This is useful if you want to just do quick dumps of the data, but not if you need to do any conversions with dates or category names.

Not sure if that helps though.

Cheers,

Alex