Error: no such collation sequence: NOCASE_UTF8 - sqlite

I m using an existing db file in sqlite3. One of the column in a particular table is having clause COLLATE NOCASE_UTF8. I m not able to insert any text in that field. its giving following error:
sqlite> INSERT INTO recording (recordingName) VALUES ('abcd');
Error: no such collation sequence: NOCASE_UTF8
How should I enter the text in it?

That's a custom collation. SQLite has native support for a collation named "NOCASE", but not for a collation named "NOCASE_UTF8". You're getting the error, I think, because there is no such collation defined in your SQLite database, but nevertheless that collation name is still stored as part of the table definition.
I'm not sure how SQLite handles storage of collations defined through the C API. But I'm pretty sure that's what you need to fix. See also the docs for Collation Needed Callbacks. (You might need only one call to sqlite3_collation_needed().)

Related

Making a column case sensitive in sql

I have created a database but now i wanted to make a column case sensitive for search purposes.
ALTER TABLE hospital_details ALTER COLUMN list COLLATE Latin1_General_CS_AS;
this is the error:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COLLATE Latin1_General_CS_AS' at line 1
Review MariaDB's syntax of ALTER TABLE here: https://mariadb.com/kb/en/alter-table/
You can use ALTER TABLE ... ALTER COLUMN only to set a default or drop a default from a column.
If you want to change the column's collation, it's ALTER TABLE ... MODIFY COLUMN but you will have to specify the whole column definition including type, default, and collation.
Also be sure that the version of MariaDB you use supports the collation you named. Use SHOW COLLATION to view the collations available. Read https://mariadb.com/kb/en/show-collation/ for details.
I don't think MySQL or MariaDB support a collation named Latin1_General_CS_AS. What reference did you get that collation name from?
MariaDB does support a collation Latin1_General_CS.

MariaDB insert error in PHP7 since upgrade from CentOS7 to Oracle Linux Server 8.6 [duplicate]

When using this query :
INSERT INTO order (order_quantity)
VALUES ('50')
I'm getting an error :
You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use
near 'order (order_quantity) VALUES('50')' at line 146
What's wrong with my query?
Reserved words are not recommended for use as database, table, column, variable or other object names. If you desire to use a reserved word is used as an object name in ANSI standard syntax, it must be enclosed in double-quotes to allow the Relational Engine (whichever that one is) that the word is being used as an object and not as a keyword in the given context.
Here are some examples specific to different SQL engines:
order is a SQL Keyword, used to sort results (ORDER BY ...)
Wrap backticks around it if you are using MySQL or Maria DB
INSERT INTO `order` (order_quantity) VALUES ('50');
Wrap brackets around it if you are using MS SQL Server
INSERT INTO [order] (order_quantity) VALUES ('50');
Wrap double quotes around it if you are using pgSQL
INSERT INTO "order" (order_quantity) VALUES ('50');
In example, nothing (but common sense) prevents you from creating a database named INSERT with a table INTO having a column VALUE(42)
Yes, this query works :
USE [INSERT];
SELECT [INTO].[VALUE(42)] FROM [INTO];

The Difference between SQLite NVARCHAR and NVARCHAR2

I don't know what is the difference between SQLite NVARCHAR and NVARCHAR2 column.
I know that NVARCHAR is a Unicode-only text column, but what about NVARCHAR2?
There is a difference. In a way...
HereĀ“s the thing:
As Lasse V. Karlsen says, SQLite does not act on the types you mentioned nor does it restrict the length by an argument passed in like in NVARCHAR(24) (but you could do check constraints to restrict length).
So why are these available in SQLite Expert (and other tools)?
This info will be saved in the database schema (please check https://www.sqlite.org/datatype3.html#affinity and http://www.sqlite.org/pragma.html#pragma_table_info) So should you bother to set these when creating a SQLite db as it will not be used by SQLite?
Yes if you will be using any tool to generate code from the schema! Maybe somebody will ask you to transfer the db to MSSQL, then there are some great tools that will use the schema and will map your SQLite to MSSQL in a blink. Or maybe you will use some .NET tool to map the tables into POCO classes, and these can also use the schema to map to the correct type and they will also use the restrictions and transfer these into data annotations on the properties that the columns map to. And EntityFramework 7 will have support built in for SQLite and their code generation will surely make use of the schema.
There is no difference.
SQLite does not operate with strict data types like that, it has "storage classes".
If you check the official documentation you'll find this rule, one of five used to determine which storage class to assign to a column from the data type you specify:
If the declared type of the column contains any of the strings "CHAR", "CLOB", or "TEXT" then that column has TEXT affinity. Notice that the type VARCHAR contains the string "CHAR" and is thus assigned TEXT affinity.
There are 5 rules in total but rule 2 covers NVARCHAR and NVARCHAR2 and both will assign the storage class TEXT to the column.

Syntax for using collate nocase in a SQLite replace function

I have an existing database where they created theiw own unicode collation sequence. I'm trying to use the following code and get a "no such collation sequence" exception. Can anybdy hlep with the the syntax to use "collate nocase" with this code?
update Songs set
SongPath = replace (SongPath, 'Owner.Funkytown', 'Jim');
Dump database (via shell), edit output SQL (find and change column definitions, set COLLATION NOCASE). Recreate database.

SQLIite - how to add special data?

I is there a way to add "additional info" to a sqlite database. Something like date of creation of a database, amount of entries or name of user who created it. If I don't want to create special tables in order to store all this info especially if there will only be one of each type.
Thank you in advance.
Why not use one special table and store each special value as a name-value pair?
CREATE TABLE SpecialInfoKeyValues (
Key VARCHAR UNIQUE COLLATE NOCASE,
Value
);
Since SQLite uses "manifest typing," you can store any kind of value you want in there.
In short, no. SQLite has no concept of users, and doesn't store creation metadata.
No, there is no way to do that, you will have to use a "special" table to carry data within the file, or you will have to use external means.
There are, however, two version counters stored within the database itself: the schema_version and the user_version (see Pragmas to query/modify version values for details.) Perhaps you could abuse those. Please keep in mind, though, that by default the sqlite3 shell application does not store those when you use the .dump command to dump the database into a textual representation.

Resources