Syntax for using collate nocase in a SQLite replace function - sqlite

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.

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];

How to use collation for pattern matching in sqlite?

For example if in the sqlite database have entries Resume, Résumé ,RESUME and if we enter
select Name from NAME_TABLE where Name like 'Re%%'
It should return all
But like does not support collation , any-other way to do pattern matching using collation ?
In SQLite, LIKE always uses the NOCASE or BINARY collations.
You could redefine LIKE by install a user-defined like() function, but you could just as well use your own function with a different name.

Using COLLATE on peewee queries

I found in the peewee documentation how to create custom collations, but I wasn't able to find how to use the built-in sqlite collating sequences.
Ho do I create the following query in peewee (it is the last one in the above mentioned sqlite documentation page)?
SELECT x FROM t1 ORDER BY c COLLATE NOCASE, x;
And how do I specify the collation for an index?
CREATE INDEX i1 ON t1(f1 COLLATE NOCASE);
EDIT
The answer from coleifer addresses the question about the query.
For the index creation I am using the following trick, which works well when you create the indexes only once at startup (like in my app).
The case insensitive unique index on two columns on the table LockedFiles prevents duplicated entries.
class LockedFiles(PeeweeModel):
folder = peewee.CharField(index=True)
file = peewee.CharField(index=True)
#classmethod
def custom_init(cls):
db.execute_sql('create unique index if not exists lockedfiles_unique '
'on lockedfiles(folder collate nocase, file collate nocase)', {})
def create_tables(drop_existing_tables):
for table in [LockedFiles, Model2, Model3]:
if drop_existing_tables:
table.drop_table(True)
table.create_table(True)
try:
table.custom_init()
except:
pass
create_tables(drop_existing_tables=False)
You can specify a collation by building up the SQL clause and passing it to order_by().
For example:
collated = Clause(MyModel.field, SQL('COLLATE NOCASE'))
MyModel.select().order_by(collated, MyModel.other_field)
For the index unfortunately you will need to create that by hand as peewee does not know how to add collation information to the CREATE INDEX SQL. If you'd like to open a pull-request I would definitely consider merging that feature, though.

Error: no such collation sequence: NOCASE_UTF8

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().)

Resources