Replacing Characters in a textfield or textArea

That.

I hope you are not always “O’Lone”. I hope you have some friends… :smiley:

Anyway, I tested with “real data” and this seems to be working fine in my real program.

Thanks to all who helped.

1 Like

Don’t find yourself “alone” in a dark alley with me someday…

it’s pronounced oh-lone, not uh-lone.

2 Likes

geeze, some people cannot take a humor!

No offense was meant!

1 Like

I think Greg WAS joking. Ah, how ironic…

1 Like

Your “bone-headed mistake” is to be doing things the hard way. Forget all the bind stuff and just use ExecuteSQL to do all that for you. So you can forget all this:

Var ps As SQLitePreparedStatement

ps = SQLitePreparedStatement(db.Prepare("INSERT INTO Activity (groupType, Name, startTime, endTime, Notes, seconds, minutes, hours, tech3, tech2, tech1) VALUES (?,?,?,?,?,?,?,?,?,?,?"))
    
    ps.BindType(0, SQLitePreparedStatement.SQLITE_TEXT)
    'ps.BindType(1, SQLitePreparedStatement.SQLITE_TEXT)
    'ps.BindType(2, SQLitePreparedStatement.SQLITE_TEXT)
    'ps.BindType(3, SQLitePreparedStatement.SQLITE_TEXT)
    'ps.BindType(4, SQLitePreparedStatement.SQLITE_TEXT)
    'ps.BindType(5, SQLitePreparedStatement.SQLITE_TEXT)
    'ps.BindType(6, SQLitePreparedStatement.SQLITE_TEXT)
    'ps.BindType(7, SQLitePreparedStatement.SQLITE_TEXT)
    'ps.BindType(8, SQLitePreparedStatement.SQLITE_TEXT)
    'ps.BindType(9, SQLitePreparedStatement.SQLITE_TEXT)
    'ps.BindType(10, SQLitePreparedStatement.SQLITE_TEXT)
    
    ps.Bind(0, TextField1.Text) // for group, with an apostrophe
    'ps.Bind(1, TextField2.Text) // for name with apostrophe
    'ps.Bind(2, "2021-04-13 21:20:20") //start time
    'ps.Bind(3, "2021-04-13 22:20:20")//end time
    'ps.Bind(4, TextArea1.Text) //notes with apostrophe
    'ps.Bind(5, "600") //seconds
    'ps.Bind(6, "10") //minutes
    'ps.Bind(7, "0.166666") //hours
    'ps.Bind(8, "Fred Flintstone") //techname
    'ps.Bind(9, "000-000-0001") //cell phone
    'ps.Bind(10, "000-000-0002")// office phone

.
and instead do something like:

sql = "INSERT INTO Activity (groupType, Name, startTime, endTime, Notes, seconds, minutes, hours, tech3, tech2, tech1) VALUES (?,?,?,?,?,?,?,?,?,?,?)"
db.ExecuteSQL (sql, TextField1.Text, TextField2.Text, "2021-04-13 21:20:20", etc etc)

Much shorter and easier to understand, and no need to worry about apostrophes AT ALL.

2 Likes

But still, make sure you are delivering UTF8 encoded strings with your statement. Always make sure you use the correct encoding/decoding while working with databases (and files). :wink:

Hi Tim.

The reason I went with prepared statements is due to the fact that in name / textarea, sometimes an apostrophe came up.
Then when I went to save to the database, it said it did, but the record was never written.
Using prepared statements seems to solve this problem for me.

But as they say, there is more than one way to skin a human… (I LIKE cats!) :smiley:

Regards

1 Like

The code I put in to replace yours DOES use prepared statements. It’s just all done internally, and as the docs say, provided you use the SelectSql and ExecuteSql instead of the old methods, you get prepared statements for FREE without having to think about them.

IOW: there almost never a need to use bind/SQLitePreparedStatement etc.

IOW?
What is IOW?

In Other Words.

1 Like