I have problem with data which I want to fetch from SQLite database in my Adobe AIR application. I use Javascript.
In sqlite3 CLI when I use this query: select * from notes;
I get this result:
Cześć|8
Boa noite|12
Até logo|13
But when I want to get this data in AIR using:
dbQuery = new air.SQLStatement();
dbQuery.sqlConnection = db;
dbQuery.text = "SELECT hello, id FROM sometable";
I have something like that:
Cze|8
Boa noite|12
At logo|13
All specific characters are removed.
Where could be problem and how can I resolve it?
I discovered where was problem.
I added new entities using sqlite3 CLI and probably the values were inserted in wrong encoding, because when I inserted values like "łąśćźóż" using AIR Adobe application or importing data to database:
sqlite3 test.db < test.sql
values are saved in correct encoding and when I get them to application, they are displayed in correct encoding.
Related
I guess that it's valid for MySQL, however, I cannot find anything about SQLite.
Basically, I have a table which is named 'CUSTOMER'.
So I create an attribute like this:
.. Image BLOB .. after that my insert statement looks like this:
INSERT INTO CUSTOMER(1,LOAD_FILE(D:/Project/Images/X.jpg));
However, the LOAD_FILE tag is not working and I don't know how to insert an image or if we can do that.
If you're using the sqlite3 shell, the relevant function is readfile().
If you're doing this from your own program, you have to read the file into a byte array and bind it as a blob to the desired column in an insert. The exact details vary depending on language and sqlite bindings, but you shouldn't ever have to convert it to a blob literal string and embed that directly into a statement.
You can store an image as a BLOB, but you'd have to insert it as a a series of bytes using something like :-
INSERT INTO CUSTOMER (image_column, other_column) VALUES(x'0001020304........','data for the first other column');
So you'd need to convert the file into a hex string to save it.
However, it's not really recommended to store images but to rather store the path to the image and then retrieve the file when you want to display/use the image.
Saying that, SQLite can, for smaller images (say 100K), actually be more efficient 35% Faster Than The Filesystem.
You must use the cmd command line (windows) to insert the attachment. The sqllitespy (version 1.9.13) does not support de command from the program command line.
You should acess you database first with the CMD and after that;
update (your table) set (column) = readfile ('dir where the files are stored'||num||´.jpg);
I'm using TFDQuery from FireDAC with SQLite database, displaying some formatted fields and I'm having problems with "printf" because TFDQuery doesn't display the data in the situation indicated below:
// THIS WORKS ON SQLite CONSOLE and doesn't work in Delphi
// With a comma separator it should show "1,234" in SQLite console and it shows "empty data" in Delphi
SELECT printf('%,d', 1234 ) AS val_tot FROM itens;
//THIS DOESN'T WORK FROM THE SQLITE CONSOLE AND SHOWS WRONG DATA IN DELPHI
// With dot separator shows '1234' in Delphi and doesn't work in SQLite console
SELECT printf('%.d', 1234 ) AS val_tot FROM itens;
Is this a TFDQuery bug or does it have some configuration for it to work?
The only thing I don't have an automated tool for when working with Oracle is a program that can create INSERT INTO scripts.
I don't desperately need it so I'm not going to spend money on it. I'm just wondering if there is anything out there that can be used to generate INSERT INTO scripts given an existing database without spending lots of money.
I've searched through Oracle with no luck in finding such a feature.
It exists in PL/SQL Developer, but errors for BLOB fields.
Oracle's free SQL Developer will do this:
http://www.oracle.com/technetwork/developer-tools/sql-developer/overview/index.html
You just find your table, right-click on it and choose Export Data->Insert
This will give you a file with your insert statements. You can also export the data in SQL Loader format as well.
You can do that in PL/SQL Developer v10.
1. Click on Table that you want to generate script for.
2. Click Export data.
3. Check if table is selected that you want to export data for.
4. Click on SQL inserts tab.
5. Add where clause if you don't need the whole table.
6. Select file where you will find your SQL script.
7. Click export.
Use a SQL function (I'm the author):
https://github.com/teopost/oracle-scripts/blob/master/fn_gen_inserts.sql
Usage:
select fn_gen_inserts('select * from tablename', 'p_new_owner_name', 'p_new_table_name')
from dual;
where:
p_sql – dynamic query which will be used to export metadata rows
p_new_owner_name – owner name which will be used for generated INSERT
p_new_table_name – table name which will be used for generated INSERT
p_sql in this sample is 'select * from tablename'
You can find original source code here:
http://dbaora.com/oracle-generate-rows-as-insert-statements-from-table-view-using-plsql/
Ashish Kumar's script generates individually usable insert statements instead of a SQL block, but supports fewer datatypes.
I have been searching for a solution for this and found it today. Here is how you can do it.
Open Oracle SQL Developer Query Builder
Run the query
Right click on result set and export
http://i.stack.imgur.com/lJp9P.png
You might execute something like this in the database:
select "insert into targettable(field1, field2, ...) values(" || field1 || ", " || field2 || ... || ");"
from targettable;
Something more sophisticated is here.
If you have an empty table the Export method won't work. As a workaround. I used the Table View of Oracle SQL Developer. and clicked on Columns. Sorted by Nullable so NO was on top. And then selected these non nullable values using shift + select for the range.
This allowed me to do one base insert. So that Export could prepare a proper all columns insert.
If you have to load a lot of data into tables on a regular basis, check out SQL Loader or external tables. Should be much faster than individual Inserts.
You can also use MyGeneration (free tool) to write your own sql generated scripts. There is a "insert into" script for SQL Server included in MyGeneration, which can be easily changed to run under Oracle.
I recently moved my mp3 library to my home folder, and this caused banshee to forget my file data (such as rating, ect). If I can update the file path in banshee's sqlite table, I can get restore my user-entered file data.
sqlite stores path data in a Uri field of the CoreTracks table.
Example:
Uri
file:///storage/Music/mp3/Genre/Artist/Album/Track.mp3
I'd like to change all instances to
file:///home/user/Music/mp3/Genre/Artist/Album/Track.mp3
Is there a safe way of changing just the first 15 characters of data contained in the Uri field?
Create the database backup. Then use the sqlite.exe command line shell. open your database like this:
sqlite rating.sqlite
> UPDATE CoreTracks SET Uri = 'file:///home/user' + substr(Uri, 17);
>
At the end press Ctrl-D to finish the sqlite console. I think I counted the characters correctly. Please double check if value 17 needs to be changed to something else
I'm using SQLite Administrator to query a blob in a table. I'm using a query that looks like this:
SELECT quote(data) FROM versions WHERE id = '....'
The blob is longer than 256 characters. When I look at the results, I'm only getting the first 256 characters back.
The blob contains XML. How do I query the database so I get the full XML back?
Tony
I ended up writing a quick WinForms application to retrieve the data from the database and put it into a TextBox control. Thanks anyway.