in

System.Data.SQLite

An open source ADO.NET provider for the SQLite database engine

SQLite error near "Reine": syntax error

Last post 01-07-2009 12:53 AM by ernie74. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 12-29-2008 4:56 PM

    SQLite error near "Reine": syntax error

    I would like to read from a XP/visual basic 2008 a db3 database using:

    BaseMPCommand.CommandText = "SELECT tblPrograms.idProgram, tblPrograms.strTitle, tblPrograms.strDescription FROM tblPrograms WHERE idProgram=" + iteration1.ToString

    table: tblPrograms
    cell: strDescription, type:text, data value for this cell: il jouit egalement des faveurs de la "reine" du bordel

    my program return an exception:

    SQLite error
    near "Reine": syntax error

    If I delete the two double quote into the cell: il jouit egalement des faveurs de la reine du bordel the program does'nt crash any more! Bug, misunderstanding, missing parameters, what could be the solution? (data is produced by an external package, and I can't modify the cell before)

     

    Many thanks for your help

     

     

  • 12-29-2008 5:11 PM In reply to

    Re: SQLite error near "Reine": syntax error

     You will want to use "parameterized" queries, which avoid problems such as this:

    http://sqlite.phxsoftware.com/forums/t/83.aspx

  • 12-30-2008 12:22 AM In reply to

    Re: SQLite error near "Reine": syntax error

    Sunshine, thanks a lot for the answer, but I am a newbie and I don't understand how the "parameterized" querie could fix this data type problem. Could you explain a little bit why with or without these double quotes in a  cell (data type text) fix this exception?

     

    thanks

     

    a little step forward!

     

    after accessing the database thru the SELECT, I update the cell using

    BaseMPCommand.CommandText = "UPDATE tblPrograms SET strDescription=" + Guillemet + Description + Guillemet + " WHERE idProgram= " + iteration1.ToString

    Description = il jouit egalement des faveurs de la "reine" du bordel,    Guillemet is double quote So the question:

     

    How to place a double quote in a text field, using a parameter and so don't interpret these double quotes?????

     

  • 12-30-2008 6:23 AM In reply to

    Re: SQLite error near "Reine": syntax error

    ernie74:

    I am a newbie and I don't understand how the "parameterized" querie could fix this data type problem. Could you explain a little bit why with or without these double quotes in a  cell (data type text) fix this exception?

    Sorry, I read your original post too hastily.  Are you certain that the SELECT statement was the cause of the SQL error, or was the problem caused by a composed INSERT or UPDATE string containing the quoted "reine"?

    ernie74:

    after accessing the database thru the SELECT, I update the cell using

    BaseMPCommand.CommandText = "UPDATE tblPrograms SET strDescription=" + Guillemet + Description + Guillemet + " WHERE idProgram= " + iteration1.ToString

    Description = il jouit egalement des faveurs de la "reine" du bordel,    Guillemet is double quote So the question:

    How to place a double quote in a text field, using a parameter and so don't interpret these double quotes?????

     

    This is the sort of issue for which parameterized queries are very helpful.With parameterized queries, your CommandText would look like:

      BaseMPCommand.CommandText = "UPDATE tblPrograms SET strDescription=@desc WHERE idProgram=@id";

     You then provide values for the paramaterized arguments like this:

      BaseMPCommand.CommandText.Parameters["@desc"].Value = Description;
     
    BaseMPCommand.CommandText.Parameters["@id"].Value = iteration1;

    With these parameterized values set up, any strange characters or quoting problems in 'Description' will be handled correctly and automatically by SQLite so that you do not have to worry about forming a properly quoted SQL string.

  • 12-31-2008 4:13 AM In reply to

    Re: SQLite error near "Reine": syntax error

    Great! Shure the faulty statment is the update. I will test your suggestion as soon as I will be back home . Any way many thanks an happy new year.

  • 01-07-2009 12:53 AM In reply to

    Re: SQLite error near "Reine": syntax error

    Many thanks for your help, the problem is fixed.

     

    BaseMPCommand.Parameters.Add(New SQLiteParameter("@ProgramReference"))

    BaseMPCommand.Parameters.Add(New SQLiteParameter("@Description"))

    BaseMPCommand.Parameters("@ProgramReference").Value = ProgramReference

    BaseMPCommand.Parameters("@Description").Value = Description

    BaseMPCommand.CommandText = "UPDATE tblPrograms SET strDescription = @Description WHERE idProgram = @ProgramReference"

Page 1 of 1 (6 items)
Powered by Community Server (Commercial Edition), by Telligent Systems