Ionut Daniel
Ionut Daniel

Reputation: 312

Empty blob insert query in ODBC c ++ (oracle)

I need to insert a blob in o oracle database. I am using c++ and ODBC library. I am stucked at the insert query and update query .It is abstract for me how to make an blob insert query. I know how to make an query for a non blob column. My table structure is :

REATE TABLE t_testblob (
     filename VARCHAR2(30) DEFAULT NULL NULL,
     apkdata  BLOB         NULL
)

I found an exemple on insert and update :

 INSERT INTO table_name VALUES (memberlist,?,memberlist)
 UPDATE table_name SET ImageFieldName = ? WHERE ID=yourId

But these structure of querys or abstract to me . What should memberlist be ? why is there "?" where are the values to be inserted ?

Upvotes: 1

Views: 687

Answers (1)

Michał Niklas
Michał Niklas

Reputation: 54292

Those question marks means that it is PreparedStatement. Such statements are good for both server and client. Server has less work because it is easier to parse such statement, and client do not need to worry about SQLInjection. Client prepares such query, builds buffer for input values and calls it.

Also such statement is executed very quick compared to "normal" queries, especially in loops, importing data from csv file etc.

I don't know what ODBC C++ library you use while ODBC is strictly C library. Other languages like Java or Python can use it too. I think the easiest is example in Python:

cursor = connection.cursor()
for txt in ('a', 'b', 'c'):
    cursor.execute('SELECT * FROM test WHERE txt=?', (txt,)) 

Of course such PreparedStatement can be used in INSERT or UPDATE statements too, and for your example it can look like:

cursor.execute("INSERT INTO t_testblob (filename, apkdata) VALUE (?, ?)", filename, my_binary_data)

Upvotes: 1

Related Questions