<cfscript>
/**
* Reads a file.
*
* @param file The filename to read.
* @param from The line number specifying where to begin reading.
* @param to The line number specifying where to stop reading.
* @param NL Character to use for newlines. Defaults to Chr(13)Chr(10)
* @return Returns a string.
* @author Raymond Camden ([EMAIL PROTECTED])
* @version 1, December 3, 2001
*/
function FileRead(filename) {
var fileStr = "";
var fileReaderClass = createObject("java", "java.io.FileReader");
var fileReader = fileReaderClass.init(filename);
var lineNumberReaderClass =
createObject("java","java.io.LineNumberReader");
var lineReader = lineNumberReaderClass.init(fileReader);
var notDone = true;
var lastLine = 0;
var thisLine = 0;
var NL = Chr(13) & Chr(10);
var from = 0;
var to = 0;
var line = "";
//optional FROM
if(arrayLen(arguments) gt 1) from = arguments[2];
//optional TO
if(arrayLen(arguments) gt 2) to = arguments[3];
//optional NL
if(arrayLen(arguments) gt 3) NL = arguments[4];
if(not fileExists(filename)) return "";
while(notDone) {
line = lineReader.readLine();
thisLine = lineReader.getLineNumber();
if( (from is 0 OR thisLine gte from) AND (to is 0 OR
thisLine lte to)) fileStr = fileStr & line & NL;
if(thisLine is lastLine) notDone = false;
lastLine = thisLine;
}
return fileStr;
}
</cfscript>
Brook Davies
logiforms.com
At 11:17 AM 4/15/2004, you wrote:
>Hi Barney,
>
>I am trying to read in a text file. The file is quite large over
>400mb. I get this file dumped to me from an external process. How can
>you break it up?
> ----- Original Message -----
> From: Barney Boisvert
> To: CF-Talk
> Sent: Thursday, April 15, 2004 12:49 PM
> Subject: RE: Import a Text file to MYSQL
>
> If you have access, change the max packet size that your server will allow.
> 1M is pretty small; we run at 16M, and we don't do anything in the way of
> batch loading. But you probably don't have that access, so you'll have to
> make sure your queries are smaller than 1M each.
>
> Just break your query down into smaller batches, and run them sequentially.
> I don't know how big the chunks can be, but if those records are
> representitive of all your data, then you can do like 13,000 records per
> query. I'd probably drop that down to a few thousand though, just to be
> safe. Not like it's going to be any more expensive.
>
> Cheers,
> barneyb
>
> > -----Original Message-----
> > From: Mickael [mailto:[EMAIL PROTECTED]
> > Sent: Thursday, April 15, 2004 9:17 AM
> > To: CF-Talk
> > Subject: Re: Import a Text file to MYSQL
> >
> > Hi,
> >
> > The is my problem my server does not allow my to use LOAD
> > DATA INFILE so I made a text file that contains my insert
> > information its called text12.txt
> > the text file looks like this with the last row with out a comma
> >
> > 733513, '2002-11-12', '6:54:01 PM', 'Automatic Debtor status
> > change to OUT.'),
> > (733513, '2002-11-12', '6:54:01 PM', 'Automatic Debtor status
> > change to OUT.'),
> > (733513, '2002-11-12', '6:54:01 PM', 'Automatic Debtor
> > status change to OUT.'),
> > (733513, '2002-11-26', '10:05:08 AM', '##6303 NO ONE BY THAT NAME'),
> >
> >
> >
> > Here is my CF Code
> >
> > Start <cfoutput>#now()#</cfoutput>
> >
> >
> > <cfquery name="GetFile" datasource="mysqldsn">
> > INSERT INTO Client_comm
> > VALUES
> > <cfinclude template="/text12.txt">
> > </cfquery>
> > <br>
> > <br>
> > <br>
> >
> >
> > End <cfoutput>#now()#</cfoutput>
> >
> > This is the error that I get back from CF
> >
> > Error during query: Unexpected Exception:
> > java.lang.IllegalArgumentException message given: Packet is
> > larger than max_allowed_packet from server configuration of
> > 1047552 bytes
> >
> > Any Ideas on how to import this many records?
> >
> > Mike
> > ----- Original Message -----
> > From: Barney Boisvert
> > To: CF-Talk
> > Sent: Tuesday, April 13, 2004 3:16 PM
> > Subject: RE: Import a Text file to MYSQL
> >
> >
> > You can use LOAD DATA INFILE if you have sufficient
> > privileges on the server
> > and the file format is acceptable. If not, it's pretty
> > simple to do some
> > text manipulation and convert text into a multi-line INSERT
> > statement:
> >
> > INSERT INTO tabl
> > (col1, col2, col3)
> > VALUES
> > ('11', '12', '13'),
> > ('21', '22', '23'),
> > ('31', '32', '33'),
> > .....
> > ('n1', 'n2', 'n3)
> >
> > Basically, it goes like this: replace all "'" with "\'",
> > add "('" to the
> > start of every line, add "')" to the end, replace "," with
> > "','", prepend
> > the INSERT .... VALUES stuff, and then remove the trailing comma.
> >
> > Cheers,
> > barneyb
> >
> > > -----Original Message-----
> > > From: Mickael [mailto:[EMAIL PROTECTED]
> > > Sent: Tuesday, April 13, 2004 12:06 PM
> > > To: CF-Talk
> > > Subject: Import a Text file to MYSQL
> > >
> > > Hello All,
> > >
> > > Can you import a text file to MYSQL with CF. I would like to
> > > take a text file that is exported to Access then Drop/Create
> > > the table with CF in MYSQL then import the file in its
> > > entirety to create the table.
> > >
> > > This sounds simple enough in theory, how can this be done in
> > > CF and MYSQL I don't really have any experience with MYSQL
> > >
> > > Thanks in advance
> > >
> > > Mike
> > >
> > >
> > >
> >
> >
> >
>
>----------
>[<http://www.houseoffusion.com/lists.cfm/link=t:4>Todays Threads]
>[<http://www.houseoffusion.com/lists.cfm/link=i:4:160165>This Message]
>[<http://www.houseoffusion.com/lists.cfm/link=s:4>Subscription]
>[<http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=905.825.4>Fast
> Unsubscribe] [<http://www.houseoffusion.com/signin/>User Settings]
>
>----------
><http://www.houseoffusion.com/banners/view.cfm?bannerid=41>
>[]
>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

