Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 11 total
Thread Filenames as variables in SQL queries
Tue, Dec 15 2009 5:32 AMPermanent Link

Sean
DBISAM Latest - D2009

I am pulling the last of my hair out. The query below works so that is not the issue. I am importing a text file to a table. No issue there. I want to
have the flexibility for the end user to specify the file name and path. Something to do with quotes, I am missing something. Any help appreciated,
cheers, Sean

  FileNameToUse := datamodule1.tblSetupLocations.FieldByName('MOImportPath').AsString;

  //Filenametouse := AnsiQuotedStr(FilenametoUse,'"'); // doesn't work
  //Filenametouse := QuotedStr(FilenametoUse);           // doesn't work
  //Filenametouse :='"C:\AMI\testdata\sdm.sdf"';          //This works
  Filenametouse :='[C:\AMI\testdata\sdm.sdf]';            //This works

  qryImport.close;
  qryImport.SQL.clear;
  qryImport.SQL.Add('IMPORT TABLE TempWeather from ');
  qryImport.SQL.Add(FilenametoUse);
  
qryImport.SQL.Add('Columns(Date,MeanWindSpdLS,MaxWindSpdLS,MeanWindDirLS,MeanWindSpdHS,MaxWindSpdHS,MaxWindDirHS,MeanSeaLeve
l1,MeanSeaLevel2,MeanSeaLevel3,');
  
qryImport.SQL.Add('MeanSeaTemp1,MeanSeaTemp2,MeanDewPoint,MeanWindChill,MaxWindChill,MeanWBGT,MaxWBGT,MeanWetBulb,MaxAirTemp
,MeanAirTemp,MinAirTemp,');
  qryImport.SQL.Add('MeanRelHum,MeanBarPress,TotalRain,CumFDD,AddFDD,Spare,DirFreq1,DirFreq2,DirFreq3)');
  showmessage(qryImport.sql.text);
  qryImport.ExecSQL;
  qryImport.Close;
Tue, Dec 15 2009 6:35 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Sean


My initial thought was D2009 = Unicode so you have a problem there. How are you obtaining FilenametoUse, what is it defined as, string or ansistring, in the versions that don't work?

What I'd suggest to help find out the problem is to build qryImport.SQL and then qryImport.SQL.SaveToFile(....), examine the text in the file, try running DBSys and see if you can spot the problem there.

Roy Lambert [Team Elevate]
Tue, Dec 15 2009 7:15 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Sean,

<< I am pulling the last of my hair out. The query below works so that is
not the issue. I am importing a text file to a table. No issue there. I want
to have the flexibility for the end user to specify the file name and path.
Something to do
with quotes, I am missing something. >>

You need double-quotes or brackets around any file names with periods or
other types of special characters, so it is usually best to just always
enclose them with double-quotes.

Thanks,

--
Tim Young
Elevate Software
www.elevatesoft.com

Tue, Dec 15 2009 7:25 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Tim

>You need double-quotes or brackets around any file names with periods or
>other types of special characters, so it is usually best to just always
>enclose them with double-quotes.

This

Filenametouse := AnsiQuotedStr(FilenametoUse,'"');

puts double quotes round the filename so I don't think that can be the problem.

Roy Lambert [Team Elevate]
Tue, Dec 15 2009 7:39 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Roy,

<< puts double quotes round the filename so I don't think that can be the
problem. >>

Yes, but he also said that this:

Filenametouse :='"C:\AMI\testdata\sdm.sdf"';          //This works

works, which is also double-quotes.  So, I believed the one that I could see
the formatting for. Smiley I suspect that the issue with AnsiQuotedStr is
something not readily apparent, but logical once realized.

--
Tim Young
Elevate Software
www.elevatesoft.com

Tue, Dec 15 2009 8:10 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Tim

<< puts double quotes round the filename so I don't think that can be the
>problem. >>
>
>Yes, but he also said that this:
>
>Filenametouse :='"C:\AMI\testdata\sdm.sdf"'; //This works
>
>works, which is also double-quotes. So, I believed the one that I could see
>the formatting for. SmileyI suspect that the issue with AnsiQuotedStr is
>something not readily apparent, but logical once realized.

You could well be right. Since I'd never used AnsiQuotedStr I tested it and the output looked fine to me which is why I suggested capturing the built up sql and having a shuftie.

Roy Lambert
Tue, Dec 15 2009 8:20 AMPermanent Link

Sean
Have tried several other combinations to no avail. Very strange behaviour. I would hate to have to hard wire the file names for these. Any other
ideas please send along. Always appreciate the great support, cheers, Sean


"Tim Young [Elevate Software]" wrote:

Roy,

<< puts double quotes round the filename so I don't think that can be the
problem. >>

Yes, but he also said that this:

Filenametouse :='"C:\AMI\testdata\sdm.sdf"';          //This works

works, which is also double-quotes.  So, I believed the one that I could see
the formatting for. Smiley I suspect that the issue with AnsiQuotedStr is
something not readily apparent, but logical once realized.

--
Tim Young
Elevate Software
www.elevatesoft.com
Tue, Dec 15 2009 8:41 AMPermanent Link

Sean
This works below... SQL dump to text file...if likes double-quotes as expected - now how do I create just the double-quotes?

IMPORT TABLE TempWeather from
"C:\AMI\testdata\sdm.sdf"
Columns(Date,MeanWindSpdLS,MaxWindSpdLS,MeanWindDirLS,MeanWindSpdHS,MaxWindSpdHS,MaxWindDirHS,MeanSeaLevel1,MeanSeaLevel2,M
eanSeaLevel3,
MeanSeaTemp1,MeanSeaTemp2,MeanDewPoint,MeanWindChill,MaxWindChill,MeanWBGT,MaxWBGT,MeanWetBulb,MaxAirTemp,MeanAirTemp,MinAi
rTemp,
MeanRelHum,MeanBarPress,TotalRain,CumFDD,AddFDD,Spare,DirFreq1,DirFreq2,DirFreq3)











Sean wrote:

Have tried several other combinations to no avail. Very strange behaviour. I would hate to have to hard wire the file names for these. Any other
ideas please send along. Always appreciate the great support, cheers, Sean


"Tim Young [Elevate Software]" wrote:

Roy,

<< puts double quotes round the filename so I don't think that can be the
problem. >>

Yes, but he also said that this:

Filenametouse :='"C:\AMI\testdata\sdm.sdf"';          //This works

works, which is also double-quotes.  So, I believed the one that I could see
the formatting for. Smiley I suspect that the issue with AnsiQuotedStr is
something not readily apparent, but logical once realized.

--
Tim Young
Elevate Software
www.elevatesoft.com
Tue, Dec 15 2009 9:25 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Sean


Try

cost dq ='"';

 qryImport.SQL.Add(dq+FilenametoUse+dq);

If that doesn't work then you have some really weird problem.

Roy Lambert
Wed, Dec 16 2009 1:29 AMPermanent Link

Sean
Bizarre concept to fool a poor system but for some reason your suggestion works. Thanks, I will try and work out why and advise. Maybe just the
allignment of the planets or something similary logical. Thanks for all the great help, as always, Sean

Roy Lambert wrote:

Sean


Try

cost dq ='"';

 qryImport.SQL.Add(dq+FilenametoUse+dq);

If that doesn't work then you have some really weird problem.

Roy Lambert
Page 1 of 2Next Page »
Jump to Page:  1 2
Image