Re: How to iterate through lines - (Re: SqlDataLoader)

Daniel Dekany <[email protected]> Thu, 24 Feb 2005 12:47:59 +0100
Newsgroups gmane.comp.text.fmpp
Message-ID <[email protected]>
Thursday, February 24, 2005, 7:26:19 AM, Ralf Hauser wrote:

> Hi,
>
> How can one easily iterate through lines of an input .txt file?
>
> I faintly remember that this is very easy with the Perl while loop, but I'd
> rather stay with fmpp and I didn't find anything in freemarker doc.

FreeMarker is not meant to be a full-blown programming language like
Perl: the preparation of the data model should be done outside the
template, that is, in this case by FMPP + a data loader. However, in
fact, this can be done in pure FreeMarker, but that would be ugly and
antipattern...

> Plan:
> =====
> I have a txt file with each line representing a relational table record. I
> want to prefix some string (SQL instruction), perhaps replace some ","  with
> "','" and terminate each line by replacing "@@@" with a closing string.
> And this needs to be written to a different outputfile (e.g. ".sql")
>
> If anyone can share an example how to do this, many thanks in advance!

The "textSequence" data loader is something in my TODO list for a long
time, and I will add it to the CVS tonight. That is similar to the
"text" data loader, just it splits the text into a sequence of strings
at a specified symbol, like for example line-break.

> Ralf
>
> Ps:
>
> Background:
> ===========
> Basically, I need the opposite of what Carl has so nicely contributed
> (Although I would call his oeuvre "SqlDataRetriever") and I would call what
> I need SqlDataUploader.
>               **
>
> He is retrieving data from sql into fmpp and I want to take data out of a
> txt file into fmpp and ultimately into a relational DB.
>
> So far, my input txt file was sufficient with MySQL and I used
>   LOAD DATA
>   INFILE './tbl_globals.txt'
>   INTO TABLE TBL_GLOBALS
>   FIELDS TERMINATED BY ','
>   LINES TERMINATED BY '@@@';
>
> Now, the data also needs to go into Oracle and I am told, it is for the few
> dozens of records easier to just do plain SQL insert statements with the
> values than to try to create a "sqlldr" .ctl input file. This is what I want
> to achieve above.
>
> The advantage of going for plain SQL is furthermore that it will be more
> portable if I next had to get it into DB2, Postgres, Daffodil, ...
>
>
> --------------
> Securely and spam-free via:
> https://www.privasphere.com/[email protected]
>
>
>
> -------------------------------------------------------
> SF email is sponsored by - The IT Product Guide
> Read honest & candid reviews on hundreds of IT Products from real users.
> Discover which products truly live up to the hype. Start reading now.
> http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
> _______________________________________________
> fmpp-open mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/fmpp-open


-- 
Best regards,
 Daniel Dekany


____________________________________________________________________
Miert fizetsz az internetert? Korlatlan, ingyenes internet hozzaferes a FreeStarttol.
Probald ki most! http://www.freestart.hu


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click