I am trying to insert a 'png ' image into an sql table field(called barchart,which is of type blob) with the below query.
INSERT INTO disease_symptom_soc(barchart) Values ((SELECT BULKColumn FROM OPENROWSET(BULK N'/home/barchartC2936861.png', SINGLE_BLOB) AS Image)) where disease_id='C2936861';
I am getting the below error.What could be the reason?
ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near '(BULK N'/home/barchart' at line 1
i guess u can use LOAD_FILE
Example:
INSERT INTO expBLOB(ID,IMAGE) VALUES(1,LOAD_FILE('/some/path/image.png'))
If you can, then change the DataType of the column to 'image'. Depending on the sql server version you are using. Otherwise if it oracle based db , you will have to create a loadfile proc and execute it as follows:
http://arjudba.blogspot.com/2008/06/how-to-insert-blob-dataimage-video-into.html
MySql OpenrowSet isn't used to copy files into the database but to query an external file (csv, xls) with a connection string, for example
OPENROWSET ('MSDASQL','mysql connection string','query')
I suggest you to load the file with a simple program made in any language (I don't know if you are developing in php, c#...) and pass it already loaded in memory to the db with a simple insert query.
Related
I can get backup file for mysql database using php and every thing gone nice , but when I trying to restore this backup file I have mysqli error
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERT INTO radpostauth VALUES ('289','ah','ah','Access-Accept','2017-08-14 10:' at line 7
in other hand when I take the query which is writed into the file and past it in php my admin directly it executed without any error I am sure that the query is right
I have 3 empty line between every insert query when I run the file the first insert query is executed but the error is show when want to execute the second insert query
INSERT INTO radcheck VALUES ('1229','ah','Cleartext-Password',':=','ah','','','','','','','','');
INSERT INTO radpostauth VALUES ('289','ah','ah','Access-Accept','2017-08-14 10:04:22'), ('290','muh','asdfghjkl','Access-Accept','2017-08-14 10:05:30'), ('291','sda','sad','Access-Accept','2017-08-14 11:21:48'), ('292','sda','sad','Access-Accept','2017-08-14 11:55:40'), ('293','sda','sad','Access-Accept','2017-08-14 11:59:03'), ('294','sda','sad','Access-Accept','2017-08-14 12:52:58'), ('295','sda','sad','Access-Accept','2017-08-14 13:41:41'), ('296','sda','sad','Access-Accept','2017-08-14 14:50:40'), ('297','sda','sad','Access-Accept','2017-08-15 09:45:40'), ('298','ah','ah','Access-Accept','2017-08-16 12:52:09'), ('299','ah','ah','Access-Accept','2017-08-17 09:19:53');
why I have this wrong
Try using mysqli::multi_query() instead of mysqli::query(). It allows the execution of multiple queries at once.
I like to get the id of the record that's been inserted by a statement as a result of that statement. I know about SELECT LAST_INSERT_ID(); but can not use it in my scenario because LAST_INSERT_ID() works on a per-connection-basis and I am currently using a convenient function in my framework to access the db - but that convenience implies that the connection only exists during execution of that statement - so I'm wondering if there is a syntax as in Microsoft SQL Server as shown in the title?
In my environment, I am building the command looks like this:
INSERT INTO Bookings (Status,YEarlyBird,YDays,YHotel,YBanquet,Name,Company,Address,Town,Region,Postcode,CountryCode,Second
Name,SecondEmail,RoomType,SpouseMealPlan,Notes,Conference_VAT,Accommodation_VAT,Conference_id,InvoiceAmount,Conferen
ceGross,Accomodation,SpouseGross,SpouseNet,TotalGross,TotalNet,ConferenceNet,Courses) VALUES (:<C1:,:<C1:,:<C6:,:<C
6:,:<C1:,:<C12:,:<C28:,:<C15:,:<C7:,:<C5:,:<C5:,:<C2:,:<C1:,:<C1:,:<C15:,:<C3:,:<C1:,:<F:,:<F:,:<I:,:<F:,:<F:,:<F:,:
<F:,:<F:,:<F:,:<F:,:<F:,:<C1:);SELECT LAST_INSERT_ID();
(the :<:-stuff are placeholders for Bind-variables)
If a ran the INSERT on its own, it works. If I append the SELECT LAST_INSERT_ID() as shown, I get:
[MySQL][ODBC 5.3(w) Driver][mysqld-5.7.18-log]You have an error in your SQL syntax; check the manual that corresponds to y
our MySQL server version for the right syntax to use near 'SELECT LAST_INSERT_ID()' at line 1
P.S: using that convient way to access the DB is perfectly ok in my use-case because the DB is written once only - exactly with the statement i am working on.
Hi i am working on scrapy and writing a pipeline and in that i had a query which should write the data in to mysql database
tx.execute("""INSERT INTO example_table (book_name,price)
VALUES (%s,%s)""",
(item['book_name'],
item['price'],)
)
I am getting the following errors two errors below
(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '))' at line 2")
(1241, 'Operand should contain 1 column(s)')
I dont know whats wrong in this query but i am unable to save the data in to database.
Can any one have a idea of this.
You forgot to add % while executing
x.execute("""INSERT INTO example_table (book_name,price)
VALUES (%s,%s)""",%
(item['book_name'],
item['price'])
)
You have added an additional comma at last remove it. following is the correct statement. Kindly try.
x.execute("""INSERT INTO example_table (book_name,price)
VALUES (%s,%s,%s,%s,%s,%s)""",
(item['book_name'],
item['price'])
)
I'm trying to insert some binary data into database using 'mysql' gem in ruby. But as the binary data contains many single and double quotes, the following code fails. Please help me to fix it.
m = mysql.prepare("insert into data (binary) values ('#{binary_data}') ")
Error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.......' at line 1 (Mysql::Error)
binary is reserved word in mysql so wrap it with apostrophe like
insert into data (`binary`) ......
You're using prepared statements wrong. What about this?
stmnt = mysql.prepare("insert into data (`binary`) values (?)")
stmnt.execute binary
i am new to the databases and i recently downloaded mysql 5.1 and learning the commands from a website. i am not able to insert the data from a file into a database. i am using the command line and typed the same command from
http://www.webdevelopersnotes.com/tutorials/sql/mysql_course_inserting_data_in_mysql_tables.php3
but it was issuing an error.. i am using windows 7.. is the file format not supported ? or the command is wrong? please help... thanks in advance
the file name is "nit.dat"... created the database named 'nitish' and a table inside it named 'stud' now i typed
mysql nitish < nit.dat ;
at the command line... and i kept the file nit.dat in the bin directory.... the file contains three records to be inserted.....
insert into stud ( id, name, age ) values ( 99, "nit", 23);
insert into stud ( id, name, age ) values (22, "nit22", 12);
insert into stud ( id, name, age ) values (10, "nit10", 56);
i am prompted with an error message showing...
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'mysql
nitish < nit.dat' at line 1 .... what to do?
Hmmm..I think I got it. Are you running MySQL already before executing that statement? In that case, the command fails. You need not have to connect to mysql and execute that query.
Refer this. The command is correct and it should work if the text file contains the INSERT query you have specified. If there is anything more then because of those query it should fail.
If you are a MySQL beginner you could try GUI tools where you don't have to worry about commands :-) Read this. You could try SQLyog which is simple and efficient.