MYSQL Update errors - mariadb

Getting errors on the following. seems simple, but can't clear this error:
NOTE: that wphz_posts.guid is a text field, not int
All table and column names are correct
"SQL Error (1064): You have an error in your SQL syntax; ‘check the
manual that corresponds to your MariaDB server version for the right
syntax to use near ' WHERE wphz_postmeta.meta key = ‘ProductURL’ AND
wphz_postmeta.post id = wphz.. at line 3
UPDATE wphz_posts
SET wphz_posts.guid = (select concat(wphz_postmeta.meta_value,"?campid=nnnnnn")
WHERE wphz_postmeta.meta_key = 'ProductURL' AND wphz_postmeta.post_id = wphz_posts.id)

Related

How to create multi-column indices DuckDB/SQLite?

I have a DuckDB with columns of data which I would like to query using multiple columns. I'm in R but I'm not sure how to create a multicolumn index (or even a single column index). Can anyone suggest a reference please? I've added SQLite as a tag because I gather that the commands could be the same.
Edit:
Based on kukuk1de's recommendation I'm trying the following
require(DBI)
require(duckdb)
DBI::dbExecute(con,statement = "CREATE INDEX multi_idx ON (percent prevalence fresh_flow maskProp dropExhale)")
but I get the following error:
Error in .local(conn, statement, ...) :
duckdb_prepare_R: Failed to prepare query CREATE INDEX multi_idx ON (percent prevalence fresh_flow maskProp dropExhale)
Error: Parser Error: syntax error at or near "("
LINE 1: CREATE INDEX multi_idx ON (percent prevalence fresh_flow maskProp...
Try this:
library("DBI")
con = dbConnect(duckdb::duckdb(), dbdir=":memory:", read_only=FALSE)
dbExecute(con, "CREATE TABLE items(item VARCHAR, value DECIMAL(10,2), count INTEGER)")
dbExecute(con, "INSERT INTO items VALUES ('jeans', 20.0, 1), ('hammer', 42.2, 2)")
dbExecute(con, "CREATE INDEX itemcount_idx ON items (item, count);")
Running the last command again will tell you the index already exists.
dbExecute(con, "CREATE INDEX itemcount_idx ON items (item, count);")
Error in duckdb_execute(res) : duckdb_execute_R: Failed to run query
Error: Catalog Error: Index with name "itemcount_idx" already exists!

Error when inserting into Database in Python

What is wrong with the code to produce this error
mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in
your SQL syntax; check the manual that corresponds to your MariaDB server
version for the right syntax to use near '%s)' at line 1
I am using XAMPP Localhost Database and mysql.connector Package in Python. My Code for Inserting:
cursor = db.cursor()
username = input()
sql = "INSERT INTO `employee` (`id`, `username`) VALUES (NULL, %s)"
cursor.execute(sql, username)
db.commit()
print("success")
Instead of this line
cursor.execute(sql, username)
try this
cursor.execute(sql, [username])
execute expects a list/(list of tuples) as the second parameter. You can have a look at the documentation if you need more details.

Mariadb syntax error on Declare statement

I am creating a MariaDB stored procedure in phpmyAdmin and I keep getting a syntax error.
I have tried appending an # symbol for the variable but I am still getting the error.
Here is what my code currently looks like:
DECLARE #cNAME = VARCHAR(100);
SET #cNAME = "TEST";
SELECT * from tblUser where UserName = cNAME;
I expect that my stored procedure would get saved but it doesn't because of the syntax error.

OperationalError: near "(": syntax error" at SQLite3

After taking a crash course for SQLite3, I tried to make a db for my first project:
import sqlite3 as db
conn = db.connect('todo.db')
cursor = conn.cursor()
cursor.execute("CREATE TABLE todo(id serial primary key, title text, created
timestamp default now(), done boolean default 'f')")
cursor.execute("INSERT INTO todo (title) VALUES('Learn web.py')")
Unfortunately I receive this error:
OperationalError: near "(": syntax error" at SQLite3
I do not understand what's wrong with the code. Can anyone explain what I am doing wrong?
As shown in the documentation, if the default value is not a simple value, it must be enclosed in parentheses:
CREATE TABLE todo(
...,
created timestamp default (now()),
done boolean default 'f'
);
(And 'f' is not a valid value for a boolean. And now() is not an SQLite function.)

Sqlite DB Error - could not prepare statement

I am getting following error on insert statement for sqlite DB
could not prepare statement (1 near "undefined": syntax error)
I tried 2 variations of insert, for both error is same
var sql = "INSERT INTO Med(MedID) VALUES(?),";
sql += "['"+dataObj[i].MedID+"']";
var sql = "INSERT INTO Med(MedID) VALUES ('"+dataObj[i].MedID+"')";
tx.executeSql(sql);
The correct way to give parameters to an SQL statement is as follows:
var sql = "INSERT INTO Med(MedID) VALUES (?)";
tx.executeSql(sql, [dataObj[i].MedID]);
It looks like you are missing the space that is needed between the table name and the column names.
Try this:
var sql = "INSERT INTO Med (MedID) VALUES ('"+dataObj[i].MedID+"')";
tx.executeSql(sql);
Make sure your dataObj[i].MedID is also defined. Add a console.log(sql) before your executeSql statement to check the command before using it.

Resources