Entity Framework and Mysql fail to insert - mysql

I'm trying to insert row to mySql db and I'm getting this 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 '(SELECT
`groups_users`.`groupID`,
`groups_u' at line 1
The Code is
groups_users ug = new groups_users();
ug.groupID = 1;
ug.userID = 1;
ug.isDeleted = false;
ug.created = DateTime.Now;
ctx.groups_users.Add(ug);
ctx.SaveChanges();
Thanks

Fixed it.
Had issue in edmx file. all fields were set to be entity keys.

Related

MySQL 5.6.41 errno 1064: Creating a MySQL query with variables

I have a (currently localhost, but soon to be through AWS) Node.JS server with Express and I'm trying to update an RDS instance through a MySQL query when I'm getting the following error:
{ [Error: ER_PARSE_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 ''history0' = 'http://localhost:3000/' WHERE id = 1' at line 1]
code: 'ER_PARSE_ERROR',
errno: 1064,
sqlMessage: '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 \'\'history0\' = \'http://localhost:3000/\' WHERE id = 1\' at line 1',
sqlState: '42000',
index: 0,
sql: 'UPDATE infected SET \'history0\' = \'http://localhost:3000/\' WHERE id = 1;' }
The POST request causing the error:
app.post('/history', function(req, res) {
var hist = 'history' + 0;
var sql = 'UPDATE infected SET ? = ? WHERE id = ?;';
connection.query(sql, [hist, req.body[0].url, 1]);
});
I'm using hist as a variable because I plan to have it in a loop, but I wasn't sure if the way I'm declaring it here is causing the issue so I left it as is. req.body is the output of JSON.stringify() called on call to chrome.history.search(). So I'm trying to get the URL of the entry at index 0.
I've tried a direct call to connection.query with a hard-coded string as follows:
connection.query("UPDATE infected SET history0='google.com' WHERE id='1'");
and it successfully updates the database, so I figure there's an issue with how I'm using the question marks to insert variables hist and req.body[0].url into the query, but I can't figure out what the issue is.
try with double "??" for the keys, this way:
app.post('/history', function(req, res) {
var hist = 'history' + 0;
var sql = 'UPDATE infected SET ?? = ? WHERE id = ?;';
connection.query(sql, [hist, req.body[0].url, 1]);
});

MySQL Syntax error in the update statement, NodeJS(MySQL2) module

I am using Node.JS along with the mysql2 module. It's basically like when I try to update a column with a JSON stingified data, I get the following error:
{ Error: 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 '"1050":1}WHERE
`user` = ?' at line 1
The stingified JSON data:
{"1050":1}
The query:
var sql = 'UPDATE `users` SET `furniture` = ' + 'concat(furniture,' + JSON.stringify(self.furniture) + ')' + 'WHERE `user` = ?';
self.furniture is related to something else, but I can assure you that self.furniture is returning that JSON data thus I get the mysql syntax error.
sqlMessage: '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 \'"1050":
Issue is resolved using backticks along with single quotes.
var sql = 'UPDATE `users` SET `furniture` = ' + `concat(furniture, '${lol}')` + 'WHERE `user` = ?';
var lol = JSON.stringify(self.furniture)
Your query line says in part
...ingify(self.furniture) + ')' + 'WHERE `us...
It should have an extra space after the close parenthesis.
...ingify(self.furniture) + ') ' + 'WHERE `us...
Here's the thing about MySQL syntax errors: the message shows the erroneous query starting with the first character MySQL does not understand. A good way to troubleshoot this kind of thing is to use console.log() to output the entire query string, then look at it carefully. You will usually find something obvious wrong.

How to append string to column

I want to append a string as a prefix to the values of a column. When I try this one:
UPDATE ortsbezug SET Zusatz = CONCAT("Nordseite",Zusatz) WHERE FSOrtID = 2425;
I always get an 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 ') FROM ortsbezug WHERE FSOrtID = 2425 AND (Zusatz <> CONCAT("Nordseite" OR Zus' at line 1
Anyone has an idea where exactly the error could be?
screenshot of query and error

Error in SQL syntax MySQLSyntaxErrorException in Grails

I do request to MySQL database, which searches data in table by criteria:
def tableAcounting(){
def user = Person.findByUsername(springSecurityService.currentUser.username)
def cafee = user.cafee
def tablesQuery = TablePlacesInfo.createCriteria()
def tables = tablesQuery.list { //AN ERROR SHOW ON THIS STRING
'in'("hall", HallsZones.findAllByCafee(cafee))
}
def halls = cafee.halls
But I get such error:
Class:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException
Message: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
This usually happends if you do an in search using an empty set. This means, that you need to check the size of HallsZones.findAllByCafee(cafee) because this set is probably empty.

SQL syntax Limit 1 error

WordPress database 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 'LIMIT 1' at line 4
for query
SELECT wp_wpsp_templates_fonts.name
FROM wp_wpsp_templates_fonts
WHERE wp_wpsp_templates_fonts.fontID =
LIMIT 1
made by
require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), include('/themes/twentyten/wpsp-sales-page.php'), require_once('/plugins/wpsp/wpsp-frontend.php'), TemplatesModel->GetFontByID
Below is the code.
function GetFontByID($fontID) {
global $wpdb;
$results = $wpdb->get_results(" SELECT ".$wpdb->prefix."wpsp_templates_fonts.name
FROM ".$wpdb->prefix."wpsp_templates_fonts
WHERE ".$wpdb->prefix."wpsp_templates_fonts.fontID = ".mysql_real_escape_string($fontID)."
LIMIT 1");
return $results[0]->name;
}
Any ideas on how to fix this issue?
GetFontByID() needs a parameter passed to it. Currently, the param appears blank.