Enforce the length of a VARCHAR in SQLite.

I have read that :

SQLite does not enforce the length of a VARCHAR. You can declare a VARCHAR(10) and SQLite will be happy to let you put 500 characters in it. And it will keep all 500 characters intact – it never truncates.

This is a big problem for me since I have to synchronise my local database with a server in MySql where varchar size limit should be respected.

I use a lot of tables and fields so checking this for each field will be a nightmare.
Any idea ?

1 Answer

  • Accepted Answer

    This is true. SQLLite's simplicity is that it doesnt behave like a fully fledged RDMBS. Its also how they manage to keep the size down! Assuming you are presenting your editable fields in TextFields, then you could tie in the maxLength to match the maximum lengths in your model to prevent the user typing more ?