Why MySql Load_File(TextFile) return BLOB string? - innodb

Windows 7, MySQL 8.0, InnoDB.
File contains ususal text, load result contains BLOB string.
select load_file('d:/temp.txt');
result: 0x62...43
Why it happens? And can i get TEXT result whithout convert()?

Related

Doesn't display data formatted in FireDAC with SQLite in Delphi 10

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?

SQLite3 WHERE clause doesn't return anything if datatype is BLOB

I'm using SQLite version 3.11.0 2016-02-15 17:29:24 3d862f207e3adc00f78066799ac5a8c282430a5f on Ubuntu 16.04
The query SELECT * FROM wordlist WHERE term like 'juliet' doesn't seem to return anything while the query SELECT * FROM wordlist WHERE cast(term as text) like 'juliet' returns as it should.
The datatype of the term column is blob which is also strange since I defined it as TEXT.
The problem doesn't occur in SQLite 3.8.10.2

SQLite - Trying to read a file with SQL which contains text with special characters causes strange symbols

I am trying to create a SQL script that can be used to generate a database with a set of data, but once I try to read the script in SQLite, special characters(specifically n with tilde) becomes unreadable by humans. Here is an example of a script with the issue:
create table if not exists person(
id integer primary key not null, --auto increment key
name text NOT NULL
);
begin transaction;
insert into person(name) values ('señor');
end transaction;
Running the Query "SELECT * FROM person;" returns the following result:
1|se├▒or
My class requires that I am able to show special symbols within the sqlite command line app. If I copy and paste the insert command into the sqlite console, then the value will be displayed properly.

Sqlite: How to cast(data as TEXT) for BLOB

I have a sqlite database from which I want to extract a column of information with the datatype BLOB. I am trying this:
SELECT cast(data as TEXT) FROM content
This is obviously not working. The output is garbled text like this:
x��Uak�0�>�8�0Ff;I�.��.i׮%�A��s�M
The data in the content column is mostly text, but may also have images (which I recognized could cause a problem if I cast as TEXT). I simply want to extract that data into a usable format. Any ideas?
You can use
SELECT hex(data) FROM content
or
SELECT quote(data) FROM content
The first will return a hex string (ABCD), the second quoted as an SQL literal (X'ABCD').
Note that there's (currently) no way of converting hexadecimal column information back to a BLOB in SQLite. You will have to use C/Perl/Python/… bindings to convert and import those.
You can write some simple script which will save all blobs from your database into files. Later, you can take a look at these files and decide what to do with them.
For example, this Perl script will create lots of files in current directory which will contain your data blob fields. Simply adjust SELECT statement to limit fetched rows as you need:
use DBI;
my $dbh = DBI->connect("dbi:SQLite:mysqlite.db")
or die DBI::errstr();
my $sth = $dbh->prepare(qq{
SELECT id, data FROM content
});
$sth->execute();
while (my $row = $sth->fetchrow_hashref()) {
# Create file with name of $row->{id}:
open FILE, ">", "$row->{id}";
# Save blob data into this file:
print FILE $row->{data};
close FILE;
}
$dbh->disconnect();

How to get full value of a blob from sqlite

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.

Resources