0

I just found a bug in the SQLite.NET library. I have a function which returns an array of strings with the contents of the Select command. The code is as follows:

string selectSQL = "SELECT id, token FROM Files WHERE (name LIKE 'Client.rar') AND (folder_id IN (SELECT id FROM Directories WHERE Path || name || '\' LIKE 'C:\Documents and Settings\Django\'))";
SQLiteCommand selectCommand = new SQLiteCommand(selectSQL, sqliteCon);
SQLiteDataReader dataReader = selectCommand.ExecuteReader();

bool results = dataReader.Read();
if (results == true)
{
    List<string> list = new List<string>();
    for (int i = 0; i < dataReader.FieldCount; i++)
    {
        string field = dataReader[i].ToString();
        list.Add(field);
    }
    string[] arr = list.ToArray();

    dataReader.Close();
    sqliteCon.Close();
    return arr;
}
else
{
    string[] arr = { "" };
    return arr;
}

To view the database using SQLite Data Browser program. The fact is that the query in the previous software works, and in my C # application returns an empty result.

Anyone know where is that? It seems that everything is correct

Greetings!

6
  • 2
    Try changing the first line to: `string selectSQL = @"SELECT id...' Commented Feb 15, 2013 at 17:48
  • what makes you think that it's a bug..? looks like you may have a issue with how you are reading from the dataReader.. also how come you don't use a While Loop, also when you debug the code.. are you getting any values in field, and in list if the arr variable is null or empty then try this instead string[] arr = {}; arr = list.ToArray();` Commented Feb 15, 2013 at 17:49
  • Some advice: if "the previous software works", then you do something, and now it doesn't work, the problem is probably in what you did and not in the previous software or the library. Commented Feb 15, 2013 at 18:13
  • @DJKRAZE Presumably he's only expecting one result which is why he's not using a while loop. But the code is a bit odd. Commented Feb 15, 2013 at 18:13
  • @DourHighArch I think what he's saying is that the query produced a result in the SQLite Data Browser, but he's not getting a result in his app (which I imagine is because of the unescaped backslashes in the query string). Commented Feb 15, 2013 at 18:14

1 Answer 1

1

I'm going to go ahead and make this an answer:

Try changing the first line to:

string selectSQL = @"SELECT id, token FROM Files WHERE (name LIKE 'Client.rar') AND (folder_id IN (SELECT id FROM Directories WHERE Path || name || '\' LIKE 'C:\Documents and Settings\Django\'))";

You have several backslashes in the string and they're going to cause issues if you don't escape them. You can, optionally, replace all the backslashes with two backslashes (\\ instead of \) and not put the @ in front of the string.

Sign up to request clarification or add additional context in comments.

1 Comment

Well, sorry!! The string of the SELECT command don't have the backslashes. I put the full select for them to see if the query was correct. The code I use is as follows: string selectSQL = "SELECT id, token FROM Files WHERE (name LIKE '"+name+"') AND (folder_id IN (SELECT id FROM Directories WHERE Path || name || '\\' LIKE '"+path+"'))";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.