Как я могу вставить данные двоичного файла в двоичное поле SQL с помощью простого оператора вставки?

Решение, которое я предложил, хрупко; это полагается на соглашение о присвоении имен django для внешних ключей.

USE information_schema;
tee mysql_output
SELECT * FROM TABLE_CONSTRAINTS WHERE CONSTRAINT_TYPE = 'FOREIGN KEY' AND TABLE_SCHEMA = 'database_name';
notee

Затем в оболочке,

grep 'refs_tablename_id' mysql_output
60
задан marc_s 6 June 2013 в 09:36
поделиться

1 ответ

If you mean using a literal, you simply have to create a binary string:

insert into Files (FileId, FileData) values (1, 0x010203040506)

And you will have a record with a six byte value for the FileData field.


You indicate in the comments that you want to just specify the file name, which you can't do with SQL Server 2000 (or any other version that I am aware of).

You would need a CLR stored procedure to do this in SQL Server 2005/2008 or an extended stored procedure (but I'd avoid that at all costs unless you have to) which takes the filename and then inserts the data (or returns the byte string, but that can possibly be quite long).


In regards to the question of only being able to get data from a SP/query, I would say the answer is yes, because if you give SQL Server the ability to read files from the file system, what do you do when you aren't connected through Windows Authentication, what user is used to determine the rights? If you are running the service as an admin (God forbid) then you can have an elevation of rights which shouldn't be allowed.

54
ответ дан 24 November 2019 в 17:35
поделиться
Другие вопросы по тегам:

Похожие вопросы: