I tried your method (as I can understand lists better than regex
and I have different numbers of fields for each record) but got
the below error (I can't see why it doesn't like <CFSET ValueList
= "">)
Any clues please
==========================================
Invalid CFML construct found on line 9 at column 26.
ColdFusion was looking at the following text:
=
The CFML compiler was processing:
an _expression_ beginning with "ValueList", on line 9, column
16.This message is usually caused by a problem in the expressions
structure.
a CFSET tag beginning on line 9, column 10.
a CFSET tag beginning on line 9, column 10.
a CFSET tag beginning on line 9, column 10.
The error occurred in
C:\Inetpub\wwwroot\Booksmith\update_records_list.cfm: line 9
7 : <CFIF Meta EQ "BOOS">
8 : <CFSET FieldList = "">
9 : <CFSET ValueList = "">
10 :
11 : <CFELSEIF Meta EQ "BOOE">
==========================================
================ You wrote ================
Hi Seamus
>>
>>You have a few people helping you already, but I thought I would
share how I would do this for a different perspective: basically,
I ask myself "how would I do this manually", then map the process
to code. I guess it helps to be able to think like a computer, but
I digress.
>>
>>An alternative to the dynamic SQL generation is provided using [
] instad of < >.
>>
>>Step 0: Get access to the file
>><CFFILE ACTION="" VARIABLE="inFile" etc etc>
>>
>>Step 1: process each line
>>This step includes recognizing that each piece of information is
on a separate line (Chr(13)&Chr(10)), and that on each line we
have the metadata (BOOS, ANAM, TNAM, etc), separated from the data
with a | character. NB: I treat things (everything!) as a list. I
don't/can't do regex in my head, I do lists.
>>
>>[CFSET Record = StructNew()]
>>
>><CFLOOP LIST="#inFile#" DELIMITERS="#chr(10)#" INDEX="aLine">
>>
>>Step 2: recognize records:
>>This step includes grabbing the metadata for subsequent use
>>Start = BOOS|
>>End = BOOE|
>>
>> <CFSET Meta = ListFirst(aLine, "|")>
>>
>>Just for fun (to handle a simple potential problem of missing
fields/data), we will dynamically create the insert SQL statement
as we go. To do this we will need 2 strings - the field list and
the value list. We may as well initialize them at the start of a
record.
>>
>>NB: to keep it simple, we are also going to treat all fields as
string. You can modify this process as you see fit.
>>
>> <CFIF Meta EQ "BOOS">
>> <CFSET FieldList = "">
>> <CFSET ValueList = "">
>>
>> [CFSET junk = StructClear(Record)]
>>
>>If it's the end of the record, we should insert it into the
database...
>>
>> <CFELSEIF Meta EQ "BOOE">
>> <CFQUERY DATASOURCE=etc etc>
>> INSERT INTO Books (#FieldLIst#) VALUES
(#ValueLIst#)
>> </CFQUERY>
>>
>> [Do your data insert here, using the key/value data from
the Record struct]
>>
>>
>>Step 3: recognize fields
>>We have tested for start and end of record, everything else is
assumed to be a field: build up the field and value lists
accordingly...
>>
>> <CFELSE>
>> <CFSET FieldData = Trim(ListRest(aLine, "|"))>
>> <CFSET FieldList = ListAppend(FieldList, Meta)>
>> <CFSET ValueList = ListAppend(ValueList,
"'#FieldData#')>
>>
>> [CFSET junk = StructInsert(Record, Meta, FieldData)]
>> </CFIF>
>>
>></CFLOOP>
>>
>>That will pretty much do want you want.
>>
>>HTH
>>Aaron
>>
>>----- Original Message -----
>>From: Seamus Campbell
>>To: CF-Talk
>>Sent: Monday, May 31, 2004 1:46 AM
>>Subject: parsing help for a slow learner
>>
>>
>>Hi
>>
>>I'm hoping some-one can help me.
>>I have to parse a file to insert data into a database, and I'm
>>stuck on the initial parsing. (I have some sort of mental block
>>when it comes to this sort of stuff)
>>
>>A sample of the file is at the bottom of this email.
>>
>>each record is starts with BOOS| and ends with BOOE|
>>
>>At the moment I am reading the file, then replacing the BOOS|
>>with a ~ and looping thru the file using the new delimiter (~)
>>This way I can get each record but I can't seem to then get each
>>field.
>>
>>I have tried:
>>
>><CFFILE file="#myFile#" action="" variable="myData">
>><cfset myDelim = "BOOS|">
>><cfset myData = Replace(myData,myDelim,"~","ALL")>
>>
>><cfloop index="myLine" list="#myData#" delimiters="~">
>>
>><cfloop index="myRecord" list="#myLine#"
>>delimiters="#Chr(10)##Chr(13)#">
>>
>><cfset Field = left(Trim(myLine),4)>
>><cfset Data = "" "|"))>
>><!--- Input data here --->
>>
>></cfloop>
>><hr>
>>
>></cfloop>
>>
>>But this seems to get BOOK and then the rest of the record ie
>>doesn't see a new line
>>
>>Any help at all would be greatly appreciated
>>
>>Seamus
>>
>>++++++++++++++++++++++++++++++++++++++++
>>BOOS|
>>BOOK|000004
>>TRAN|D
>>ANAM|ROTH, WALTER E.
>>TNAM|NORTH QUEENSLAND ETHNOGRAPHY Bulletin No.4 : GAMES, SPORTS
AND
>>AMUSEMENTS
>>PBLS|Home Secretary's Department Brisbane, 1902
>>SUB1|ABORIGINAL CULTURE, AUSTRALIA HISTORY, NATIVE MONOGRAPHS,
19TH
>>CENTURY SPORTS
>>DESC|Good. 1st. 13.25 x 8.25. a Monograph of 39pp, illustrated by
>>photograph and drawings, the endpapers have browned and the
>>exceedingly plain covers have surface tarnish but a bright
>>interior on superior paper. Walter E.Roth was Queensland's
>>"Northern Protector of Aboriginals" previously he was "Demy of
>>Magdalen College, Oxford".
>>PRIC|35
>>UPDT|10/05/2004
>>UPTM|12:44:38 PM
>>BCAT|Sold
>>ABLE|1
>>UBID|1
>>STAT|Sold
>>PPRC|0
>>PDSC|QLD
>>BOOE|
>>BOOS|
>>BOOK|000015
>>TRAN|A
>>ANAM|Paul De Nooijer
>>TNAM|Magie in De Vleeshal : De Fotografie Van Paul De Nooijer
>>PBLS|Middleburg: Deze Publikatie, 1987
>>SUB1|PAUL DE NOOJIER, NETHERLANDS PHOTOGRAPHER, DUTCH PHOTOGRAPHY
,
>>DRAMATIC VISUAL ART
>>DESC|Illustrated Card. Very Good. 1st. Softcover. 8.5 x 9.25.
50pp
>>with triple expanding heart "111 Kleurprints". A major art work
by
>>an icon Dutch photgrapher, covers a little rubbed. "In all my
work
>>I have wanted to involve the framework in the representation so
as
>>to suggest what is taking place behind it."
>>PRIC|25
>>UPDT|8/05/2004
>>UPTM|1:36:35 PM
>>BCAT|Art
>>ABLE|1
>>UBID|3
>>STAT|For Sale
>>PPRC|0
>>PDSC|art
>>BOOE|
>>BOOS|
>>BOOK|000018
>>TRAN|A
>>ANAM|A H Archibald Henry Rea, Illustrated by Max Cowper
>>TNAM|LINDORES ABBEY and It's Historic Associations
>>PBLS|Dundee: James P. Mathew, 1902
>>SUB1|LINDORES ABBEY, ECCLESIASTICAL ARCHITECTURE, SCOTTISH PILES
>>MAX COWPER
>>DESC|Illustrated Boards. Good. 1st. Travel and Historic Guide.
7.25
>>x 5. 153pp, a.e.g. rubs to the bottom extremities bumps to the
>>spine edges. 15 illus. and a ground plan. "Of all the valleys in
>>Scotland, perhaps not one surpasses the valley of the Tay for
>>beauty of scenery, grandeur of surroundings, and wealth of places
>>famous in the annals of our country."
>>PRIC|20
>>UPDT|8/05/2004
>>UPTM|1:46:32 PM
>>BCAT|England / Ireland / Scotland / Wales
>>ABLE|1
>>UBID|4
>>STAT|For Sale
>>PPRC|0
>>PDSC|ENG
>>BOOE|
>>BOOS|
>>BOOK|000022
>>TRAN|A
>>ANAM|NORMAN BUCHANAN
>>TNAM|Learn to Draw
>>PBLS|London: Frederick Warne, 1964
>>SUB1|ART EDUCATION, BECOMING AN ARTIST, LEARNING TO DRAW,
>>DESC|Illustrated Boards. Very Good/Fair. 1st. 11.25 x 8.5. 66pp,
>>d/w : worn, amateur repairs. clipped. Book : slight darkening of
>>the paper. sections include Ways and Means, Teaching Yourself -
>>Practical, Further Practice Out of Doors, Figure Drawing. "One of
>>the ideas running through this book is that if a student can make
>>a really good drawing of a potato.."
>>PRIC|22.5
>>UPDT|8/05/2004
>>UPTM|11:50:22 AM
>>BCAT|Art
>>ABLE|1
>>UBID|5
>>STAT|For Sale
>>PPRC|0
>>PDSC|art
>>BOOE|
>>++++++++++++++++++++++++++++++++++++++++
>>
>>Seamus Campbell Boldacious WebDesign
>>http://www.boldacious.com ~~~~ [EMAIL PROTECTED]
>>ph 02 6297 4883 mob 0410 609 267
>>
>>
>>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

