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

前端 未结 2 967
[愿得一人]
[愿得一人] 2020-12-17 14:19

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<

2条回答
  •  太阳男子
    2020-12-17 14:58

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

提交回复
热议问题