Indigo Rose Software

Professional Software Development Tools

 
Results 1 to 10 of 10
  1. #1
    Join Date
    Mar 2006
    Location
    Corpus Christi, Texas
    Posts
    132

    SQL Cannot write to db using a apstrophy

    by using
    ReadMessage = Input.GetText("WriteInput");

    WriteInput = I'm here

    it will not write to the db.

    It will write everthing else even ? " [ = + @ and so on but will not write a apstrophy.

    Please help

  2. #2
    Join Date
    Apr 2005
    Location
    In Wonderworld
    Posts
    246
    Are you trying to write the input from and input object to a db file?

  3. #3
    Join Date
    Mar 2006
    Location
    Corpus Christi, Texas
    Posts
    132
    If i understand you correct then yes.


    I type in a Input box and submit it

    and it tries to write what i typed to the db but if i type in a apstrophy it will error.

    I can type anything else and it works fine.


  4. #4
    Join Date
    Apr 2005
    Location
    In Wonderworld
    Posts
    246
    I thouth you were writing it to a DatabaseFile with strings,
    like this example
    Code:
    ReadMessage = Input.GetText("WriteInput");
    TextFile.WriteFromString("Autoplay\\Docs\\MyDatabase.db", ""..ReadMessage, false);
    cause that option works with apostrophe,
    i havent used experimented with sqlite very much and so in that way i dont know if it works or not, hoppefully someone more knowlegable in this area will help you out,

  5. #5
    Join Date
    Nov 2001
    Location
    Portland, OR USA
    Posts
    39

    Lightbulb Use Worm's Enclose function

    To quote the all-knowing Worm:

    "You need to enclose the string that contains the ' in quotes (")
    I like to use a function to do it to keep it a little cleaner"

    function Enclose(sIn)
    return "\""..sIn.."\"";
    end

    Enclose("You're string here...")

  6. #6
    Join Date
    May 2005
    Posts
    1,115
    You need to use StringReplace() to replace all instances of the ' with two ' of a same kind:

    I'm happy. -----> I''m happy.

    This is because of the SQL syntax.

    You see, if you don't replace ' with two 's, your query would end up like this, for example:

    Code:
    UPDATE table SET myvalue='I'm happy';
    ...which is not good. This is the correct syntax:

    Code:
    UPDATE table SET myvalue='I''m happy.';
    ...which will save I'm happy. string into your SQLite database.
    Last edited by bule; 06-01-2006 at 10:50 AM.
    Never know what life is gonna throw at you.
    (Based on a true story.)

  7. #7
    Join Date
    Mar 2006
    Location
    Corpus Christi, Texas
    Posts
    132
    I don't understand

    Name = Label.GetText("Login");
    Date = Label.GetText("Date");
    Time = Label.GetText("Time");
    ReadMessage = Input.GetText("WriteInput");
    ToUser = ComboBox.GetText("ComboBox");
    OpenMessageDatabase();

    Light = 0;

    sQuery = "INSERT into Message values(NULL, '" .. Name .. "', '" .. Date .. "', '" .. Time .. "', '" .. ToUser .. "', '" .. ReadMessage .. "', '" .. Light .. "')";

    AddRow = WriteToDB(db, sQuery);
    if AddRow == "OK" then
    end

    CloseMessageDatabase();

    How would i write that?

  8. #8
    Join Date
    Mar 2006
    Location
    Corpus Christi, Texas
    Posts
    132
    ok

    so i just
    Replace
    ReadMessage = Input.GetText("WriteInput");
    for
    ReadFirst = Input.GetText("WriteInput");
    And add this
    ReadMessage = String.Replace(ReadFirst, "'", "''", false);

    Works Nice, thanks

    Is there any others i should know about?
    Last edited by jfxwave; 06-01-2006 at 05:01 PM.

  9. #9
    Join Date
    May 2005
    Posts
    1,115
    I myself use this function to overcome this:

    Code:
    function Q(s)
    	return String.Replace(s.."", "'", "''", false);
    end
    I use it like this in the SQL queries:

    Code:
    sQuery = "INSERT into Message values(NULL, '" .. Q(Name) .. "', '" .. Q(Date) .. "', '" .. Q(Time) .. "', '" .. Q(ToUser) .. "', '" .. Q(ReadMessage) .. "', '" .. Q(Light) .. "')";
    Never know what life is gonna throw at you.
    (Based on a true story.)

  10. #10
    Join Date
    Oct 2004
    Location
    East, South & West Asia
    Posts
    1,020

    About Single Quote and Double Quotes

    Hi,

    function Enclose(sValue)
    return String.Replace(s.."", "'", "''", false);
    end

    I find it is easy to Enclose the data that has Single Quotes when INSERTing into the SQLite DB. It is also easy to SELECT......and dump it on the screen.

    BUT when making that data as the primary SELECT variable, it will not work.

    For example:

    SELECT Hobby WHERE Name=sName

    If variable sName has been Enclose() earlier , there will be SQL error when making it as the primary SELECT variable.

    Any thoughts?
    Newbie Examples
    ------> AMS 7.5 : amstudio.azman.info
    ----> AMS 6 & 5: www.azman.info/ams/
    ----> FB: facebook.com/GuideToWealth

    ----> Content Development Blog: www.AZMAN.asia

Similar Threads

  1. Microsoft SQL Server 2005 Express Edition
    By linuxbox in forum Setup Factory 7.0
    Replies: 0
    Last Post: 12-25-2005, 07:55 PM
  2. AMS app that can read and write SQL data
    By sferguson in forum AutoPlay Media Studio 5.0
    Replies: 14
    Last Post: 11-03-2004, 08:20 AM
  3. SQL - Easy does it
    By Intrigued in forum AutoPlay Media Studio 5.0
    Replies: 0
    Last Post: 08-22-2004, 09:48 PM
  4. selecting sql server
    By necabettin in forum Setup Factory 6.0
    Replies: 1
    Last Post: 05-13-2004, 09:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts