I've a SqLite linked server on SQL Server 2008.
I need to import an image column from SQL Server into my SQLite database.
Is that possible?
If yes in what kind of SQLite column to I need?
I need to transform ..... I think
Please help me
From: here
NULL. The value is a NULL value.
INTEGER. The value is a signed integer, stored in 1, 2, 3, 4, 6, or 8 bytes depending on the magnitude of the value.
REAL. The value is a floating point value, stored as an 8-byte IEEE floating point number.
TEXT. The value is a text string, stored using the database encoding (UTF-8, UTF-16BE or UTF-16LE).
BLOB. The value is a blob of data, stored exactly as it was input.
and, from: here
image: Variable-length binary data from 0 through 2^31-1
(2,147,483,647) bytes.
I suppose that BLOB should be your needed type
edit:
by the way be careful with the "image" type:
Important
ntext, text, and image data types will be removed in a future version of MicrosoftSQL Server. Avoid using these data types in new development work, and plan to modify applications that currently use them. Use nvarchar(max), varchar(max), and varbinary(max) instead.
Image column equivalent in SQLite would be BLOB.
You can accomplish your import task by writing script which connects to both SQL Server and SQLite database, then reads data from one and inserts it into another.
When you insert your data, be sure to use prepared statements and bind variables with proper data type. For example, if using Perl, use SQL_BLOB binding:
use DBI qw(:sql_types);
my $dbh = DBI->connect("dbi:SQLite:my.db");
my $blob = `cat foo.jpg`; # you should read it from SQL Server here
my $sth = $dbh->prepare("INSERT INTO mytable VALUES (?)");
$sth->bind_param(1, $blob, SQL_BLOB);
$sth->execute();
Related
While migrating a SQL Server database to Oracle, I end up with an error
ORA-12899: value too large for column
though the datatypes are the same.
This is happening with strings like 'enthält'. The data type NVARCHAR(7) should be able to hold the given string in SQL Server where as on Oracle VARCHAR2(7) not able to hold the value and throwing value too large error.
Is this something with the encoding style on Oracle? How can we resolve this?
Thanks
You can create your Oracle table with something like varchar2(7 char) this causes it to allocate in units of characters, not bytes.
This succeeds:
create table tbl(x varchar2(7 char));
insert into tbl values ('enthält');
How to verify that whether a column is an encryption key/value or plain text in SQL Server 2008?
Cell or column level encryption in SQL Server 2008 is an external operation - meaning SQL Server doesn't actually know it is encrypted. You create the key, read plaintext data in original type, encrypt and write cipher text as varbinary type back to the table. That means if you complete the process, you'll have a new column of varbinary type.
There are no catalog views you can query since as far as SQL Server is concerned, it is just another varbinary column. There are ways to figure it out manually by checking the length and/or type of the column if the original type is not varbinary. You might also check actual values or use regular expressions if you want to verify per row instead of the entire column. If the original type is varbinary, this is probably not the best place to design a solution.
I googled but failed to find an answer for the following question.
I have a DB2 database column of datatype “Char(100) for BIT Data“. It stores encrypted value of employee ID. I need to store this data in SQL Server.
What should be the datatype for this column in SQL Server?
Is there any formatting needed before inserting into SQL Server?
The column in your DB2 table is an ordinary character string, except that the for BIT Data part tells DB2 to treat that string as arbitrary binary data, rather than text. This matters mainly for sorts and comparisons. DB2 (as normally configured) would sort and compare strings alphabetically. A capital A would come before a lowercase b. But for BIT Data strings are compared by the underlying numeric value of the characters. Capital A would come after lowercase z.
In SQL server, there is a BINARY datatype for this, so you would probably use BINARY(100). No formatting should be necessary, as you probably want the value of raw binary data to stay exactly the same.
Using CakePHP 1.3.11 and SQL Server 2005 and the included MSSQL database driver.
I need to retrieve a varchar(8000) field, however the typical find() queries truncate this field to 256 characters; the actual array value array['comment'] is truncated, so the data beyond character 256 isn't accessed by my application at all.
I tried changing the field to a text datatype and with that change the query returns the full value of the column. Is there a way for cake to read the full value of the column or does it always truncate varchars to 256 characters?
Solution has been to use the text data type on the database side.
I post this question has followup of This question, since the thread is not recieving more answers.
I'm trying to understand if it is possible to pass as a parameter of a CLR stored procedure a large amount of data as "0x5352532F...".
This is to avoid to send the data directly to the CLR stored procedure, instead of sending ti to a temporary DB field and from there passing it as varbinary(max) parmeter to the CLR stored procedure.
I have a triple question:
1) is it possible, if yes how? Let's say i want to pass a pdf file to the CLR stored procedure (not the path, the full bits that make up the file). Something like:
exec MyCLRStoredProcs.dbo.insertfile
#file_remote_path ='c:\temp\test_file.txt' ,
#file_contents=0x4D5A90000300000004000.... --(this long list is the file content)
where insertfile is a stored proc that writes to the server path (at file_remote_path) the binary data I pass as (file_contents).
2) is it there corruption risk of adopting this approach (or it is the same approach that sql server uses behind the scenes)?
3) how to convert the content of a file into the "0x23423..." hexadecimal representation
What is your goal? Are you trying to transfer a file from the client filesystem to the server filesystem? If so, you might want to look at a web service file transfer mechanism.
Do you want to persist the data into the database? If so, and you have access to SQL Server 2008, I recommend looking at the new FILESTREAM type. This type maintains the link between the database and the file system for you.
Alternatively, if you don't have SQL Server 2008, you get to choose between saving it as a file and maintaining a string path to it in the database or storing the contents of a file in a VARBINARY(MAX) column.
If all you want is to get the data into the database, you don't need a CLR proc. You can save it directly to the database, or you can code a SQL stored proc to do so.
Assuming you keep the approach of sending this to a CLR proc:
1) is it possible, if yes how?
Sure, why not. The code you wrote looks like a good example. The stored proc will need to convert the string into bytes.
2) is it there corruption risk of adopting this approach
I'm not sure what you mean here. Will SQL Server randomly replace characters in your string? No. Might you accidentally hit some sort of limit? Yes, possibly; the maximum size of NVARCHAR(MAX) is 2^31-1, or 2,147,483,647 characters. But I doubt you'd have a PDF that size. Might you lose the link between the file on disk and the database path to it? Yes, though FILESTREAM should take care of that for you.
3) how to convert the content of a file into the "0x23423..." hexadecimal representation
There are many examples on the Internet on how to do this. Here's one:
How do you convert Byte Array to Hexadecimal String, and vice versa?