Home > Back-end >  Does Flutter write on SQLite with UTF-8 or UTF-16?
Does Flutter write on SQLite with UTF-8 or UTF-16?

Time:08-18

What happens when I write on a SQLite db? Does Flutter write UTF-16 strings or convert them to UTF-8?

And when I read? Does Flutter find UTF-16 strings or find UTF-8 strings and convert them back to UTF-16?

CodePudding user response:

Since Flutter doesn't have a native SQLite API, I assume you are referring to sqflite.

Under the hood, sqflite relies on the MethodChannel class to communicate with the SQLite APIs. Whenever a method is invoked, a query or a command will go through the MethodChannel via the native invokeMethod.

invokeMethod is called on the MethodChannel class, and invokeMethod essentially executes a call to SQLite using binary.

But if you look closely at the documentation and the code. Since a codec wasn't specified when initiating the MethodChannel class it will use the StandardMethodCodec by default.

If you look within the code comments closely, it states that a String will encode into a UTF-8 format. While this does not answer your question directly, you can assume that given the information available, Flutter encodes String to UTF-8 before sending it to SQLite and vice-versa.

I don't have definitive answers for other data types though, but guessing that it uses UTF-8 too isn't too far-fetched of a guess.

  • Related