|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Tab delimited input into database
Good Day
I am working on a project that requires inserting content from tab delimited files into a access database, the files are contained in a zip file that is sent from a different server every night with a the name of the zip file being the date it was sent on (02-07-05.zip), the files in the zip file are tab delimited files, but they are called; - 02-07-05.M - 02-07-05.O - 02-07-05.P Each file contants the original column information that of course will not have to be entered. I have created 3 tables in my database to store this information called members, offices, and people. The content in each file are not consistent, for example one of the column are called age, the value rage from 16, 24, 30 and OLD (it is in text form) also some column values are left blank. Each time I need to insert the content into the database (every night) the old content has to be completed removed and then re-entered, because items are removed and new items are entered frequently. Any Suggestions Review of what needs to be done: - Zipped file has to be unzipped - open each file - wipe old data and database - enter content from files (allow for empty data) - remove unzipped files from server - done every night around midnight (Run the script as a schedule task) - try to keep the load on server low I have tried many different processes for inserting the data from the file but my mane problem that I have come across is the empty values. Any help you can give will be greatly appreciated. |
|
#2
|
|||
|
|||
|
All you need to do is loop over the tab-delimited data, using the tab character as the delimiter for a list loop. Then each iteration of the loop is one tab-delimited line of the file. Insert each one into the database.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
|
#3
|
|||
|
|||
|
How can I go about doing that, without putting too much load on the server, there will be about 200 results that will have to be added every night, would not create a new connection to the database every time I run the CFQUERY function?
|
|
#4
|
|||
|
|||
|
No, ColdFusion maintains database connections unless you have explicitly unchecked that box when you created the datasource. And no, running 200 insert statements will not do anything to your server. If it was 20,000 inserts then you'd have to worry.
|
|
#5
|
|||
|
|||
|
ok thats good then, one last question concerning this item, some of the colums contain empty values and useing this coding setup:
Code:
<cfloop index="record" list="#fileData#" delimiters="#chr(10)##chr(13)#">
<cfquery name="qryInsert" datasource="whatever">
INSERT INTO tablename (COL1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12)
VALUES (
<cfqueryparam value="#listgetat(record,1,chr(9))#" cfsqltype="cf_sql_varchar">,
<cfqueryparam value="#listgetat(record,2,chr(9))#" cfsqltype="cf_sql_varchar">,
<cfqueryparam value="#listgetat(record,3,chr(9))#" cfsqltype="cf_sql_varchar">,
<cfqueryparam value="#listgetat(record,4,chr(9))#" cfsqltype="cf_sql_numeric">,
<cfqueryparam value="#listgetat(record,5,chr(9))#" cfsqltype="cf_sql_numeric">,
<cfqueryparam value="#listgetat(record,6,chr(9))#" cfsqltype="cf_sql_numeric">,
<cfqueryparam value="#listgetat(record,7,chr(9))#" cfsqltype="cf_sql_numeric">,
<cfqueryparam value="#listgetat(record,8,chr(9))#" cfsqltype="cf_sql_numeric">,
<cfqueryparam value="#listgetat(record,9,chr(9))#" cfsqltype="cf_sql_numeric">,
<cfqueryparam value="#listgetat(record,10,chr(9))#" cfsqltype="cf_sql_numeric">,
<cfqueryparam value="#listgetat(record,11,chr(9))#" cfsqltype="cf_sql_numeric">,
<cfqueryparam value="#listgetat(record,12,chr(9))#" cfsqltype="cf_sql_varchar">
)
</cfquery>
</cfloop>
the last value returns an error saying that the list only has 11 items, I am sure that I have done this before, but how could I do a simple check to see if each list item has a value? Thank you |
|
#6
|
|||
|
|||
|
you could get the ListLen to get the number of elements in the list. if its less than 12 then do your error checking stuff.
|
|
#7
|
|||
|
|||
|
But if the list has only 11 entries, you will probably need to check every one of the list positions to determine which one is missing, otherwise you'll always be assuming that it's the last one in the list when it may in fact not be.
|
|
#8
|
|||
|
|||
|
This should be a simple question but how would I be able to check all of them to ensure each colum had a value, kiteless.
|
|
#9
|
|||
|
|||
|
ColdFusion ignores empty lis elements. So if your list contains of 3 elements and one of them is empty (i.e. element1,,element2) then ColdFusion would threat that as an 2-elemental list.
Maybe replacing the empty elements in the list with "", or whatever empty value would be satisfying for your need, could help you out. |
|
#10
|
|||
|
|||
|
There are also some custom list functions at cflib.org that deal with lists without merging empty list elements together as the built-in CFML list functions do.
|
|
#11
|
|||
|
|||
|
I found what I needed to do thank you.
|
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > Tab delimited input into database |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|