"David Bicking" wrote...
> On Wed, 2009-02-11 at 16:12 -0500, jose isaias cabrera wrote:
>> "P Kishor" wrote...
>>
>>
>> > On Wed, Feb 11, 2009 at 2:00 PM, jose isaias cabrera
>> > <[email protected]> wrote:
>> >>
>> >>
>> >> "P Kishor" wrote...
>> >>
>> >>
>> >>> On Wed, Feb 11, 2009 at 1:48 PM, jose isaias cabrera
>> >>> <[email protected]> wrote:
>> >>>>
>> >>>> Greetings and salutations...
>> >>>>
>> >>>> I am having a problem with an specific UPDATE. One of the functions
>> >>>> of
>> >>>> my
>> >>>> program is to capture all of the files in a directory so that one
>> >>>> can
>> >>>> search
>> >>>> on a file name and find out where that file is quickly. This is
>> >>>> working
>> >>>> perfectly, until there is a file that has a single quote (') in its
>> >>>> name.
>> >>>> Say a directory has these three files:
>> >>>>
> <snip>
>
>> I am using D, and the statement to get all the files from a directory and
>> subdirectories is,
>>
>> char[][] dfiles = std.file.listdir(dir,"*");
>>
>> this will return an array of char[] that will contain all of the files in
>> the directory from. I then do a foreach and create a string and return
>> that
>> string. Here is the function...
>>
>> char[] GetListOfAllFilesInDir(char[] dir)
>> {
>>
>> info.text = "Getting list of files in directory...";
>> char[][] dfiles = std.file.listdir(dir,"*");
>> char[] s = "\n";
>> foreach (char[] f; dfiles)
>> {
>> char[] fn = std.path.getBaseName(f);
>> if (fn[0 .. 1] == ".")
>> {
>> if (std.file.exists(f))
>> std.file.remove(f);
>> continue;
>> }
>> if (fn[$ - 4 .. $] == ".bak" ||
>> fn[$ - 4 .. $] == ".bk1" ||
>> fn[$ - 4 .. $] == ".bk2")
>> {
>> if (std.file.exists(f))
>> std.file.remove(f);
>> continue;
>> }
>> else if(std.string.find(fn,".backup.fm") > 0 ||
>> std.string.find(fn,".backup.book") > 0)
>> {
>> if (fn[$ - 12 .. $] == ".backup.book" || fn[$ - 10 .. $] ==
>> ".backup.fm")
>> {
>> if (std.file.exists(f))
>> std.file.remove(f);
>> continue;
>> }
>> }
>> else if(std.string.find(fn,".rtf.backup") > 0)
>> {
>> if (fn[$ - 11 .. $] == ".rtf.backup")
>> {
>> if (std.file.exists(f))
>> std.file.remove(f);
>> continue;
>> }
>> }
>> else if (std.string.tolower(std.path.getExt(f)) == "msg")
>> {
>> char[] str0 = r"\d+T_";
>>
>> if (RegExp(str0).find(fn) == 0) // if filename starts with
>> 1123232343434T_
>> {
>> // No need to tag it with time. Already has been tagged...
>> }
>> else
>> {
>> char[] saveF = f;
>> char[] nf0 = std.string.toString(std.date.getUTCtime()) ~ "T_"
>> ~
>> fn;
>> char[] dn0 = std.path.getDirName(f); // Parent directory
>> dn0 = dn0 ~ r"\" ~ nf0;
>> //msgBox("1. " ~ saveF ~ "\n2. " ~ dn0,"Testing...");
>> std.file.rename(saveF,dn0);
>> fn = nf0;
>> }
>> }
>> if (std.string.find(s,"\n" ~ fn) == -1) // No filename repeats
>> s ~= fn ~ "\n";
>> }
>> //s = std.string.strip(s);
>> //msgBox(s);
>> return s;
>> }
>>
>> after this, I will prepare s and UPDATE Xtra3. Here is the question: the
>> original UPDATE should have worked, correct? Meaning that the
>> filename'3.txt should have been prepared as filename''3.txt, correct?
>>
>
> How is the list in "s" being inserted in to the update statement. Are
> you using string concatenation, then preparing the result, or are you
> using "?" in the sql and calling bind to insert the text?
>
> If the former, I don't see where you are escaping the "'" in the
> filename. The latter would not need to be escaped.
when I said prepared, I meant escaped sorry about that. After this
function, I escape it with this other function,
char[] PrepareSQLiteString(char[] s)
{
if (std.string.find(s,"'") >= 0)
{
char[][] str = std.string.split(s,"'");
s = "";
foreach (char[] s0; str)
{
s ~= s0 ~ "''";
}
s = s[0 .. $ - 2];
}
return s;
}
and I did an SQL command dump of the string that I am passing to the D
SQLite wrapper and it is escaped. I am reclining on the idea that it is the
D wrapper. I have to go to post this on the D wrapper newsgroup.
Thanks for the help,
josé
josé
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users