It's hard to say because of the kind of data put into the database at a certain insertion.
I do not know if you have heard of this term "MVC", but it you have, I would like to first of all say that this quote problem lies with the Control, not the Model.
Put it this way—let's say I have a intelligent application that indexes the name of items in my house daily at midnight and puts it into a database, given that this application is smart enough to come up with proper names of the various items. One day my friend Bob comes over and forgot to take his shades home when he leaves. So at midnight my application runs and notes the item that Bob left as:
Bob's shades
And then it uses this SQL statement to store the item into the database: INSERT INTO [ItemTable] ([ItemName]) VALUES ('Bob's shades');
Look carefully at the statement now. The SQL interpreter in the database will take the underlined portion as a string: INSERT INTO [ItemTable] ([ItemName]) VALUES ('Bob's shades');
And the rest of it as trailing characters—error!
This is why it is important to escape the single quotes, and this can only be done at your Controller. As mentioned several times before, the escape for a single quote is two single quotes, one after another. Assuming that I fixed my application, this should be the correct SQL statement: INSERT INTO [ItemTable] ([ItemName]) VALUES ('Bob''s shades');
Now, the database will store the intended string: INSERT INTO [ItemTable] ([ItemName]) VALUES ('Bob''s shades');
Many naïve implementations of database applications overlook this problem. This is especially so for the ignorant who just learnt how to develop a web application together with SQL and are starting out in some e-commerce site. Throw in one single quote in a string field and all hell breaks loose. Worse still, throw in a smart programmer/hacker and look—assuming this is the supposed statement for a search query on the e-commerce site (the underlined "pencil" is a variable term): SELECT FROM [Products] WHERE LOWER([ProdName]) LIKE '%pencil%';
And I put this string '; DELETE FROM [Products] WHERE [ProdName] LIKE ' : SELECT FROM [Products] WHERE LOWER([ProdName]) LIKE '%'; DELETE FROM [Products] WHERE [ProdName] LIKE '%';
There goes your database! You might wonder a hacker does his/her job, well basically, it is through loopholes such as this. This technique is also known as "SQL injection," simple yet very deadly.
That's why Sun provides its SQL framework for Java, and Microsoft its ADO.NET framework. These frameworks (if you know how to use them properly) does the mundane job of ensuring safe input into your database. I especially love Microsoft's ADO.NET—if you know how to use it, it makes database application developmentso quick, so easy.
So now, in regard to Sul's SQL statement, I do not know the nature of the information being inserted into the database, or I could give a better suggestion (he gave a very general SQL statement). The quotes do matter—but notice that he did not include the VALUES part of the insert statement. I would believe that he would append the VALUES part later on, completing the statement. Otherwise that might be the very reason he's getting the problems—insertion without fulfilling the data integrity rules on NOT NULL and primary key fields.