I use Sqlite on Android with Android Studio.
Select * From MyTable ORDER BY MyStringField COLLATE LOCALIZED
returns correct order with local characters.
On ios i use Xcode 13 and swift.sqlite
But there is no LOCALIZED option on queries.
There is Binary option which is not working.
Returns strings which are starting with local characters returns at the end.
How do i perform language specific collation on sqlite.swift on ios
Regards
Related
I have a table with approximately 8 million rows in it. It has a uniqueness constraint on a column called Customer_Identifier. This is a varchar(10) field, is not the primary key, but is unique.
I wish to retrieve some customer rows from this table using SQL Developer. I have been given a text file with each record containing a search key value in the columns 1-10. This query will need to be reused a few times, with different customer_identifier values. Sometimes I will be given a few customer_identifier values (<1000 of them). Sometimes many (between 1000 and 10000 of them). For the times when I want fewer than 1000 values, it's pretty straightforward to use an IN clause. I can edit the text file to wrap the keys in quotes and insert commas as appropriate. But SQL developer has a hard limit of 1000 values in an IN clause.
I only have read rights to the database, so creating and managing a new physical table is out of the question :-(.
Is there a way that I can treat the text file as a table in Oracle 12.1, and thus use it to join to my customer table on the customer_identifier column?
Brgds
Chris
Yes, you can treat a text file as an external table. But you may need DBA assistance to create a new directory, if you don't have access to a directory defined in the database.
Thanks to Oracle Base
**Create a directory object pointing to the location of the files.**
CREATE OR REPLACE DIRECTORY ext_tab_data AS '/data';
**Create the external table using the CREATE TABLE..ORGANIZATION EXTERNAL syntax. This defines the metadata for the table describing how it should appear and how the data is loaded.**
CREATE TABLE countries_ext (
country_code VARCHAR2(5),
country_name VARCHAR2(50),
country_language VARCHAR2(50)
)
ORGANIZATION EXTERNAL (
TYPE ORACLE_LOADER
DEFAULT DIRECTORY ext_tab_data
ACCESS PARAMETERS (
RECORDS DELIMITED BY NEWLINE
FIELDS TERMINATED BY ','
MISSING FIELD VALUES ARE NULL
(
country_code CHAR(5),
country_name CHAR(50),
country_language CHAR(50)
)
)
LOCATION ('Countries1.txt','Countries2.txt')
)
PARALLEL 5
REJECT LIMIT UNLIMITED;
**Once the external table created, it can be queried like a regular table.**
SQL> SELECT *
2 FROM countries_ext
3 ORDER BY country_name;
COUNT COUNTRY_NAME COUNTRY_LANGUAGE
----- ---------------------------- -----------------------------
ENG England English
FRA France French
GER Germany German
IRE Ireland English
SCO Scotland English
USA Unites States of America English
WAL Wales Welsh
7 rows selected.
SQL>
In iOS 11, if you use sqlite3_column_name with SQL with subselect statements, it now returns the column name with the table prefix, whereas iOS 10 does not.
E.g. consider this SQL:
SELECT f.foo_value, b.bar_value
FROM foo as f LEFT JOIN
(SELECT * FROM bar) AS b ON f.foo_id = b.foo_id
If you then retrieve the column names with sqlite3_column_name (note this is Objective-C snippet, but this is a SQLite issue, not unique to Objective-C or Swift):
const char *name1 = sqlite3_column_name(statement, 0);
const char *name2 = sqlite3_column_name(statement, 1);
NSLog(#"SQLite version: %s", sqlite3_version);
NSLog(#"name of column 0: %s", name1);
NSLog(#"name of column 1: %s", name2);
In iOS 11.1, this reports:
SQLite version: 3.19.3
name of column 0: f.foo_value
name of column 1: b.bar_value
In iOS 10.1, this reports:
SQLite version: 3.14.0
name of column 0: foo_value
name of column 1: bar_value
Why?
BTW, this issue appears to only manifest itself when the SQL contains subselect statements.
As the SQLite documentation for sqlite3_column_name says:
The name of a result column is the value of the "AS" clause for that column, if there is an AS clause. If there is no AS clause then the name of the column is unspecified and may change from one release of SQLite to the next.
So, if you want to use the result of sqlite3_column_name for anything other than informational purposes, you really should use the AS clause in your SQL, e.g.
SELECT f.foo_value AS foo_value, b.bar_value AS bar_value
FROM ...
As Gwendal Roué noted, this is a known issue introduced in the version of SQLite included with iOS 11:
This change has been introduced in SQLite 3.19.0. It is present in SQLite 3.19.3 shipped with iOS 11. It has been reverted in SQLite 3.20.0.
For more information, see:
Ticket: https://sqlite.org/src/info/de3403bf5ae5f72ed
Mailing-list: http://mailinglists.sqlite.org/cgi-bin/mailman/private/sqlite-users/2017-July/073955.html
SQLite 3.20.0 release notes: https://sqlite.org/changes.html#version_3_20_0
Can somebody please tell me what is the problem with the following informix statement :
SELECT * FROM
(some big query here)
INTO EXTERNAL empdata(selected_date date, land char, grund integer, some_user varchar, nr decimal(15))
USING (DATAFILES("DISK:/usr1/tbodan.out"))
I get a syntax error near INTO EXTERNAL empdata.
UPDATE
Informix version is 11.7 and omitting the column definition only brings the following error Error: Virtual column must have explicit name.
You need to follow the documented syntax at INTO EXTERNAL clause.
I think your problem is that you tried to provide column names and data types for the table.
This SQL worked for me:
SELECT * FROM elements
INTO EXTERNAL ext_elements
USING (DATAFILES("DISK:/Users/jleffler/tmp/ext-elements.table"))
This SQL did not, generating a -201 "A syntax error has occurred" error:
SELECT * FROM elements
INTO EXTERNAL ext_elements(atomic_number INTEGER, symbol CHAR(3),
name CHAR(20), atomic_weight DECIMAL(8,4),
pt_period SMALLINT, pt_group CHAR(2), stable CHAR(1))
USING (DATAFILES("DISK:/Users/jleffler/tmp/ext-elements.table"))
Testing on a Mac running macOS Sierra 10.12.5, using Informix 12.10.FC4.
Ok,so the problem was actually in the select query.
The query returns more columns that do not have an explicit name and are tagged as "expression" that is why the Error: Virtual column must have explicit name. popped up.
I solved this by using aliases for those columns. Then used the syntax suggested here.
Is there an easy way to create auto increment field using Firebird? I have installed the FlameRobin admin tool, but the process of creating an auto increment field through the tool is complex. Can I not create such an identity field just by clicking a checkbox or using some other tool other than Flamerobin?
Firebird 3 and later
In Firebird 3 it is easy to create, as it introduced identity columns. In practice it is syntactic sugar for generating a sequence + trigger (as shown for Firebird 2.5) for you.
For example
create table t1 (
id integer generated by default as identity primary key
)
Firebird 3 only supports "generated by default", which means users are able to specify their own id values (which might lead to duplicate value errors); "generated always" has been added in Firebird 4.
See also the Firebird 3 release notes, section "Identity Column Type", and the Firebird 4.0 Language Reference, section "Identity Columns (Autoincrement)".
Firebird 2.5 and earlier
Firebird 2.5 and earlier do not have auto-increment fields. You need to create them yourself with a sequence (aka generator) and a trigger.
Sequence is the SQL standard term and generator is the historical Firebird term; both terms are available in the Firebird DDL syntax.
To create a sequence:
CREATE SEQUENCE t1_id_sequence;
To create a trigger to always generate the id on a table T1 with primary key ID:
set term !! ;
CREATE TRIGGER T1_AUTOINCREMENT FOR T1
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
NEW.ID = next value for t1_id_sequence;
END!!
set term ; !!
See also: How to create an autoincrement column?
Using FlameRobin
FlameRobin also provides tooling to create a sequence + trigger for you. If you have an existing table, you can follow these steps:
Open the table properties:
Open the column properties of the primary key column
Default column properties, select new generator and create trigger:
Generator (sequence) and trigger code generated by FlameRobin. Note that contrary to my example above this trigger allows a user to specify their own id value, with some logic to avoid future duplicates. Execute this (and don't forget to commit):
I have a note field of string type in one of my models in my sqlite3 database, but I realized that I needed to store more text than string would allow.
I just ran a migration changing the type of the field from string to text. Looking at my database, it says that the type is now text(255), whereas before it was varchar(255).
What does the 255 mean? Is that a character limit? If so, would I have the same storage problems as before? How would I fix this?
Here is the migration I used to change the field type
change_column(:posts, :note, :text)
SQLite does not enforce text storage limits. If you declare a column VARCHAR(1) or TEXT(1) you still can store some very long blob of 500 Megabytes inside it. Even though that is not adviseable.
~$ sqlite
SQLite version 3.7.2
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table foo ( bar text(3));
sqlite> insert into foo values ('aeiou');
sqlite> select * from foo;
aeiou
You should just make your storage type text and not put any limit on it. The 255 denotes the maximum number of characters allowed in the field.