Recent

Author Topic: [SOLVED] SQLite: Encoding / Decoding?  (Read 412 times)

EganSolo

  • Sr. Member
  • ****
  • Posts: 302
[SOLVED] SQLite: Encoding / Decoding?
« on: April 15, 2025, 02:18:14 am »
For context, I'm converting a Protégé ontology into an SQLite-powered app. During the migration phase, I need to keep using Protégé until the new app is up and running. Therefore, I'm writing code that can take a .pins file and turn it into an SQLite script.

Why is that relevant to my question? I want a script to execute in a SQLite admin tool until the app is up and running. Therefore, I'm not using parametrized queries to load the data; I'm writing Insert-into statements.

Which brings me to my question: Are there characters that require special handling for SQLite, such as single quotes, backslashes, etc.? Are there ready-made encoders/decoders to/from SQLite into strings?

As always, I appreciate your input.
« Last Edit: April 16, 2025, 09:50:49 am by EganSolo »

Khrys

  • Full Member
  • ***
  • Posts: 227
Re: SQLite: Encoding / Decoding?
« Reply #1 on: April 15, 2025, 01:27:47 pm »
The only character with special meaning inside an SQLite string literal is the single quote. Newlines and null bytes have no effect. If security isn't an issue, then simply duplicating every single quote should do the trick.

And if your data is already present in a table and you insist on not using parametrized queries, there's the  quote()  built-in function for turning text into a string literal.

EganSolo

  • Sr. Member
  • ****
  • Posts: 302
Re: SQLite: Encoding / Decoding?
« Reply #2 on: April 16, 2025, 09:50:31 am »
Thanks Khyrs,

  I figured as much, but wanted to make sure.
  Incidentally, I __insisted__ on not using parametrized queries during the export process of the data. The new program I'm building will use them  :)

  Cheers,

 

TinyPortal © 2005-2018