Doctrine2 Criteria() generate wrong MySQL query - mysql
when I use \Doctrine\Common\Collections\Criteria::create()
use Doctrine\Common\Collections\Criteria;
...
$criteria = Criteria::create();
$criteria->where(Criteria::expr()->eq('isPublished', 1))
->andWhere(Criteria::expr()->eq('isDeleted', 0));
$this->comments->matching($criteria)
and I getting error:
Message:
An exception occurred while executing 'SELECT t0.id AS id1, t0.rating AS rating2, t0.text AS text3, t0.username AS username4, t0.isPublished AS isPublished5, t0.isDeleted AS isDeleted6, t0.dateCreated AS dateCreated7, t0.userIP AS userIP8, t0.user_id AS user_id9, t0.product_id AS product_id10 FROM product_comments t0 WHERE ((t0.isPublished IS ? AND t0.isDeleted IS ?) AND t0.product_id IS ?)' with params {"1":1,"2":0,"3":1123}:
SQLSTATE[42000]: Syntax error or access violation: 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 '1 AND t0.isDeleted IS 0) AND t0.product_id*IS 1123)' at line 1
The problem is operand 'IS' in where clausule. It is not MySQL operand. (If I paste this query to MySQL terminal, and change "IS" => "=" - is all right)
Why Doctrine genetate such query? Where is the problem?
I solved changing line 91 of Doctrine\ORM\Persisters\BasicEntityPersister
from
Comparison::IS => 'IS %s',
to
Comparison::IS => '= %s',
This is a bug in doctrine fixed by upgrading Doctrine ORM to 2.3.5 or later.
Bug report at http://www.doctrine-project.org/jira/browse/DDC-2471
More discussion on the problem at
https://github.com/doctrine/collections/commit/3db3ab843ff76774bee4679d4cb3a10cffb0a935#diff-757942c669bf6be9910786b2558ad745
Try replacing
expr()->eq('isPublished', 1) and expr()->eq('isPublished', 0) with
expr()->eq('isPublished', '?1')
expr()->eq('isPublished', '?0')
Related
Error While formating a mysql statement which includes a regular expression
Am trying to retrieve data from a Mysql table i get an error while applying string formatting techniques First try, results an error 1.service= "Dynamic value" st="SELECT Name FROM servicetable WHERE hsubservices={0} and Contact REGEXP '[A-Z]{2}|Texas|\s[0-9]{5}'".format(service) The error which occured here is Index out of range for tuple , yes i get it the '{}' in regular expression are being considered as values of tuple service="Dynamic Value" error=mysql.connector.errors.ProgrammingError: 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 'Value and Contact REGEXP '[A-Z]{2}|Texas|\s[0-9]{5}'' st="SELECT DoctorsName FROM dev_healthservices WHERE hsubservices= %s and Contact REGEXP '[A-Z]{2}|Texas|\s[0-9]{5}'"%(service) mydb=mysql.connector.connect( host = "", user = "", passwd = "", database = "" ) mycursor=mydb.cursor() mycursor.execute(st)
What does this mysql error means?
I get the following error: 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 'AND `hackcount` >= 3' at line 1 SQL=SELECT COUNT(*) from `xxxxx_mi_iptable` WHERE ip = AND `hackcount` >= 3 What does this mean? What should I do to fix this?
There's an error in your WHERE clause: WHERE ip = AND `hackcount` >= 3 Where ip equals what, exactly? You forgot to put a value there.
Looks like you're using Joomla plugin "Marco's SQL Injection" (http://www.mmleoni.net/sql-iniection-lfi-protection-plugin-for-joomla). It has a line that tries to detect the IP of the current client $remoteIP = $_SERVER['REMOTE_ADDR']; Because REMOTE_ADDR is not always present/reliable/sufficient the following SQL query $sql = "SELECT COUNT(*) from `#__mi_iptable` WHERE ip = '{$remoteIP}' AND `hackcount` >= {$this->p_ipBlockCount}" ; fails. the plugin should use something like this if (isset($_SERVER['REMOTE_ADDR'])) { $remoteIP = $_SERVER['REMOTE_ADDR']; } elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $remoteIP = $_SERVER['HTTP_X_FORWARDED_FOR']; } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) { $remoteIP = $_SERVER['HTTP_CLIENT_IP']; }
How do I fix this SQL syntax error, I cannot find it
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 'INSERT INTO ******_sports_teams (******_team_id, ******_content_type_id, ******' at line 2 That is the error I get to this script; The stars cover the name of the company I work for that I cannot release, but they are all the same word that I know is spelled correctly. SELECT * FROM `******_sports_teams` WHERE 1 INSERT INTO ******_sports_teams (******_team_id, ******_content_type_id, ******_content_type_desc, ******_sport_name, ******_sport_confernece, ******_sport_division, ******_sport_city, ******_sport_team) VALUES (1,4,'Sports','NBA','Eastern','Atlantic','Boston','Celtics'), (2,4,'Sports','NBA','Eastern','Atlantic','Brooklyn','Nets'), (3,4,'Sports','NBA','Eastern','Atlantic','Newy York','Knicks'), (4,4,'Sports','NBA','Eastern','Atlantic','Philedelphia','76ers'), (5,4,'Sports','NBA','Eastern','Atlantic','Toronto','Raptors'), (6,4,'Sports','NBA','Eastern','Central','Chicago','Bulls'), (7,4,'Sports','NBA','Eastern','Central','Cleveland','Cavaliers'), (8,4,'Sports','NBA','Eastern','Central','Detriot','Pistons'), (9,4,'Sports','NBA','Eastern','Central','Indiana','Pacers'), (10,4,'Sports','NBA','Eastern','Central','Milwaukee','Bucks'), (11,4,'Sports','NBA','Eastern','Southeast','Atlanta','Hawks'), (12,4,'Sports','NBA','Eastern','Southeast','Charlotte','Hornets'), (13,4,'Sports','NBA','Eastern','Southeast','Miami','Heat'), (14,4,'Sports','NBA','Eastern','Southeast','Orlando','Magic'), (15,4,'Sports','NBA','Eastern','Southeast','Washington','Wizards'), (16,4,'Sports','NBA','Western','Southwest','Dallas','Mavericks'), (17,4,'Sports','NBA','Western','Southwest','Houston','Rockets'), (18,4,'Sports','NBA','Western','Southwest','Memphis','Grizzlies'), (19,4,'Sports','NBA','Western','Southwest','New Orleans','Pelicans'), (20,4,'Sports','NBA','Western','Southwest','San Antonio','Spurs'), (21,4,'Sports','NBA','Western','Northwest','Denver','Nuggets'), (22,4,'Sports','NBA','Western','Northwest','Minnesota','Timber Wolves'), (23,4,'Sports','NBA','Western','Northwest','Oaklohoma City','Thunder'), (24,4,'Sports','NBA','Western','Northwest','Portland','Trail Blazers'), (25,4,'Sports','NBA','Western','Northwest','Utah','Jazz'), (26,4,'Sports','NBA','Western','Pacific','Golden State','Warriors'), (27,4,'Sports','NBA','Western','Pacific','Los Ageles','Clippers'), (28,4,'Sports','NBA','Western','Pacific','Los Ageles','Lakers'), (29,4,'Sports','NBA','Western','Pacific','Pheonix','Suns'), (30,4,'Sports','NBA','Western','Pacific','Sacremento','Kings'), (31,4,'Sports','MLB','American','East','Tampa Bay','Rays'), (32,4,'Sports','MLB','American','East','New York','Yankees'), (33,4,'Sports','MLB','American','East','Baltimore','Orioles'), (34,4,'Sports','MLB','American','East','Toronto','Blue Jays'), (35,4,'Sports','MLB','American','East','Boston','Red Socks'), (36,4,'Sports','MLB','American','Central','Kansas City','Royals'), (37,4,'Sports','MLB','American','Central','Minnesota','Twins'), (38,4,'Sports','MLB','American','Central','Detriot','Tigers'), (39,4,'Sports','MLB','American','Central','Cleveland','Indians'), (40,4,'Sports','MLB','American','Central','Chicago','White Sox'), (41,4,'Sports','MLB','American','West','Houston','Astros'), (42,4,'Sports','MLB','American','West','Texas','Rangers'), (43,4,'Sports','MLB','American','West','Los Ageles','Angels'), (44,4,'Sports','MLB','American','West','Seattle','Mariners'), (45,4,'Sports','MLB','American','West','Oakland','Athletics'), (46,4,'Sports','MLB','National','East','New York','Mets'), (47,4,'Sports','MLB','National','East','Washington','Nationals'). (48,4,'Sports','MLB','National','East','Atlanta','Braves'), (49,4,'Sports','MLB','National','East','Philedelphia','Phillies'), (50,4,'Sports','MLB','National','East','Miami','Marlins'), (51,4,'Sports','MLB','National','Central','St. Louis','Cardinals'), (52,4,'Sports','MLB','National','Central','Pittsburg','Pirates'), (53,4,'Sports','MLB','National','Central','Chicago','Cubs'), (54,4,'Sports','MLB','National','Central','Cincinnati','Reds'), (55,4,'Sports','MLB','National','Central','Milwaukee','Brewers'), (56,4,'Sports','MLB','National','West','Los Ageles','Dodgers'), (57,4,'Sports','MLB','National','West','San Francisco','Giants'), (58,4,'Sports','MLB','National','West','Arizona','Diamondbacks'), (59,4,'Sports','MLB','National','West','San Diego','Padres'), (60,4,'Sports','MLB','National','West','Colorado','Rockies'), (61,4,'Sports','NFL','NFC','East','Dallas','Cowboys'), (62,4,'Sports','NFL','NFC','East','New York','Giants'), (63,4,'Sports','NFL','NFC','East','Philedelphia','Eagles'), (64,4,'Sports','NFL','NFC','East','Washington','Redskins'), (65,4,'Sports','NFL','NFC','West','Arizona','Cardinals'), (66,4,'Sports','NFL','NFC','West','San Francisco','49ers'), (67,4,'Sports','NFL','NFC','West','Seattle','Seahawks'), (68,4,'Sports','NFL','NFC','West','St. Louis','Rams'), (69,4,'Sports','NFL','NFC','North','Chicago','Bears'), (70,4,'Sports','NFL','NFC','North' ,'Detriot','Lions'), (71,4,'Sports','NFL','NFC','North' ,'Green Bay','Packers'), (72,4,'Sports','NFL','NFC','North' ,'Minnesota','Vikings'), (73,4,'Sports','NFL','NFC','South','Atlanta','Falcons'), (74,4,'Sports','NFL','NFC','South', 'Carolina','Panthers'), (75,4,'Sports','NFL','NFC','South','New Orleans','Saints'), (76,4,'Sports','NFL','NFC','South','Tampa Bay','Buccaneers'), (77,4,'Sports','NFL','AFC','East','Buffalo','Bills'), (78,4,'Sports','NFL','AFC','East','Miami','Dolphins'), (79,4,'Sports','NFL','AFC','East','New England','Patriots'), (80,4,'Sports','NFL','AFC','East','New York','Jets'), (81,4,'Sports','NFL','AFC','West','Denver','Broncos'), (82,4,'Sports','NFL','AFC','West','Kansas City','Chiefs'), (83,4,'Sports','NFL','AFC','West','Oakland','Raiders'), (84,4,'Sports','NFL','AFC','West','San Diego','Chargers'), (85,4,'Sports','NFL','AFC','North' ,'Baltimore','Ravens'), (86,4,'Sports','NFL','AFC','North' ,'Cleveland','Browns'), (87,4,'Sports','NFL','AFC','North','Pittsburg','Steelers'), (88,4,'Sports','NFL','AFC','North' ,'Cincinnati','Bengals'), (89,4,'Sports','NFL','AFC','South','Houston','Texans'), (90,4,'Sports','NFL','AFC','South','Indianapolis','Colts'), (91,4,'Sports','NFL','AFC','South','Jacksonville','Jaguars'), (92,4,'Sports','NFL','AFC','South','Tennessee','Titans'), (93,4,'Sports','NHL','NHL','Central','Chicago','Blackhawks'), (94,4,'Sports','NHL','NHL','Central','Colorado','Avalanche'), (95,4,'Sports','NHL','NHL','Central','Dallas','Stars'), (96,4,'Sports','NHL','NHL','Central','Minnesota','Wild'), (97,4,'Sports','NHL','NHL','Central','St. Louis','Blues'), (98,4,'Sports','NHL','NHL','Central','Winnipeg','Jets'), (99,4,'Sports','NHL','NHL','Central','Nashville','Predators'), (100,4,'Sports','NHL','NHL','Pacific','Anaheim' ,'Ducks'), (101,4,'Sports','NHL','NHL','Pacific','Arizona','Coyotes'), (102,4,'Sports','NHL','NHL','Pacific','Clagary','Flames'), (103,4,'Sports','NHL','NHL','Pacific','Edmonton','Oilers'), (104,4,'Sports','NHL','NHL','Pacific','Los Ageles','Kings'), (105,4,'Sports','NHL','NHL','Pacific','San Jose','Sharks'), (106,4,'Sports','NHL','NHL','Pacific','Vancouver','Canucks'), (107,4,'Sports','NHL','NHL','Atlantic','Boston','Bruins'), (108,4,'Sports','NHL','NHL','Atlantic','Buffalo','Sabres'), (109,4,'Sports','NHL','NHL','Atlantic','Detriot','Red Wings'), (110,4,'Sports','NHL','NHL','Atlantic','Florida','Panthers'), (111,4,'Sports','NHL','NHL','Atlantic','Montreal','Canadiens'), (112,4,'Sports','NHL','NHL','Atlantic','Ottawa','Senators'), (113,4,'Sports','NHL','NHL','Atlantic','Tampa Bay','Lightning'), (114,4,'Sports','NHL','NHL','Atlantic','Toronto','Maple Leafs'), (115,4,'Sports','NHL','NHL','Metropolitan','Corolina','Hurricanes'), (116,4,'Sports','NHL','NHL','Metropolitan','Columbus','Blue Jackets'), (117,4,'Sports','NHL','NHL','Metropolitan','New Jersey','Devils'), (118,4,'Sports','NHL','NHL','Metropolitan','New York','Islanders'), (119,4,'Sports','NHL','NHL','Metropolitan','New York','Rangers'), (120,4,'Sports','NHL','NHL','Metropolitan','Philedelphia','Flyers'), (121,4,'Sports','NHL','NHL','Metropolitan','Pittsburg','Penguins'), (122,4,'Sports','NHL','NHL','Metropolitan','Washington','Capitals')
you have a dot (.) instead of a comma (,) at the end of the line with ID 47: (47,4,'Sports','MLB','National','East','Washington','Nationals'). Change it to (47,4,'Sports','MLB','National','East','Washington','Nationals'),
You have a period at the end of this line: (47,4,'Sports','MLB','National','East','Washington','Nationals'). It should be a comma
Your error message show us, that two queries does not separated with ; Just remove Select query, or add ; after it. Then, double check syntax, or read next error message. You have points instead of comma somewhere. Your first query retrieve all data from the table. It's: SELECT * FROM `******_sports_teams` WHERE 1 It should terminated with semicolon before you call next (INSERT) query
Python 3, SQLAlchemy, MySQL. Incorrect syntax in INSERT statement
Engine = create_engine("mysql+mysqldb://blah-blah-blah", encoding="utf-8") Session = sessionmaker(bind = Engine) ses = Session() Meta = MetaData(bind = Engine, reflect = True) PersonTable = Meta.tables["person"] class Person(object): pass mapper(Person, PersonTable) APerson = Person("1111", "2222", "1.01.1980") ses.add(APerson) ses.commit() sqlalchemy.exc.ProgrammingError: (ProgrammingError) (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 '%s, %s, %s)' at line 1") b'INSERT INTO person (Name, OriginalName, DoB) VALUES (%s, %s, %s)' ('1111', '2222', '25.01.1980') What is the %s? What do I wrong? Python 3.1 SQLAlchemy 0.6.5 MySQL 5.1 Windows 7 Ultimate Thank you.
You sqlalchemy commit is trying to issue an insert query that is not compatible with the schema. near '%s, %s, %s)' means your trying to insert invalid data. I can only speculate that it is because the date format - this is not the proper mysql date format YYYY-MM-DD.
I migrated back to Python 2.7. Now it works fine.
What's wrong with my sql query?
INSERT INTO jos_race_calendrier_regional (id, evt_code, evt_date_comp, evt_station, evt_activite, evt_comite, evt_club_num, evt_club_nom, evt_nom, evt_dt, org_nom, org_adresse, org_adresse2, org_adresse3, org_ville, org_site, cont_nom, cont_tel, cont_gsm, cont_fax, cont_mail, epr_codex, epr_date, epr_sexe, epr_regroupement, epr_grille_categorie, epr_categorie, epr_discipline, epr_distance, epr_homologation') VALUES ( '79', 'evt_code', 'evt_date_comp', 'evt_station', 'evt_activite', 'evt_comite', 'evt_club_num', 'evt_club_nom', 'evt_nom', 'evt_dt', 'org_nom', 'org_adresse1', 'org_adresse2', 'org_adresse3', 'org_ville', 'org_site', 'cont_nom', 'cont_tel', 'cont_gsm', 'cont_fax', 'cont_mail', 'epr_codex', 'epr_date', 'epr_sexe', 'epr_regroupement', 'epr_grille_categorie', 'epr_categorie', 'epr_discipline', 'epr_distance_style', 'epr_homologation') i am getting following error #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 '') VALUES ( '79', 'evt_code', 'evt_date_comp', 'evt_station', 'evt_activite', 'e' at line 1
The error message has already told you where your syntax error is (near), so you should look at your code again to find out what's wrong yourself, but I'll just pinpoint it to the very character for you now. You have a misplaced single quote here: epr_homologation') VALUES Should be epr_homologation) VALUES
Extra quote after epr_homologation: INSERT INTO jos_race_calendrier_regional (id, evt_code, evt_date_comp, evt_station, evt_activite, evt_comite, evt_club_num, evt_club_nom, evt_nom, evt_dt, org_nom, org_adresse, org_adresse2, org_adresse3, org_ville, org_site, cont_nom, cont_tel, cont_gsm, cont_fax, cont_mail, epr_codex, epr_date, epr_sexe, epr_regroupement, epr_grille_categorie, epr_categorie, epr_discipline, epr_distance, epr_homologation) VALUES ( '79', 'evt_code', 'evt_date_comp', 'evt_station', 'evt_activite', 'evt_comite', 'evt_club_num', 'evt_club_nom', 'evt_nom', 'evt_dt', 'org_nom', 'org_adresse1', 'org_adresse2', 'org_adresse3', 'org_ville', 'org_site', 'cont_nom', 'cont_tel', 'cont_gsm', 'cont_fax', 'cont_mail', 'epr_codex', 'epr_date', 'epr_sexe', 'epr_regroupement', 'epr_grille_categorie', 'epr_categorie', 'epr_discipline', 'epr_distance_style', 'epr_homologation')
Also, if 'id' is an int, you don't put '' around it.