I am using a portal system on my website and modified the ASP code heavily.
Since the website is growing, I want to migrate from MS Acces to MySQL.
Now, I think the portal I'm using (and some code I inputted) aren't MySQL compatable, because when I switch to the MySQL database, I get the following error.
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[MySQL][ODBC 5.1 Driver][mysqld-5.1.55-community]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 '[EzModuleID],
[ModName] From EzCore_Plugin Where IsModActive='1'' at line 1
[website]\WWWROOT\BOXX\INCLUDES../../includes/include.asp, line 3736
The SQL string regarding this line is the following:
Select [EzModuleID], [ModName] From EzCore_Plugin Where [IsModActive] = 1;
Im new to MySQL and I can't find why this is giving an error.
I've tried the quote's around 1, removing [], removing the space..
I think that when I figure out why this is causing an error, I can continue modifying the rest to make the website work on mysql.
Lose the square brackets
(I might as well post this as the answer rather than a comment)
In MySQL column and table names can be escaped with the backtick character ` or if the ANSI SQL mode is enabled with double quotes ".
Your WHERE clause (according to the error message) is Where IsModActive='1'. This works if IsModActive is a text column. If it is numeric, drop the single quotes. If IsModActive is a Boolean, change the clause to Where IsModActive IS true.
See: is operator
Related
Here is my simple query:
my $SQLp = "SELECT MAX([PawnPayments].[CreationTimeDate]) as MaxTransDate
FROM [PawnSafeDBCE].[dbo].[PawnPayments]
INNER JOIN [PawnSafeDBCE].[dbo].[PawnPaymentDetails]
ON [PawnPayments[.[PaymentID] = [PawnPaymentDetails].[PaymentID]
WHERE [PawnPaymentDetails].[TicketID[ = '$TicketID'
AND [PawnPaymentDetails].[StoreID] ='$StoreID'
Note that query is written on Perl engine. I keep receiving an error that says:
"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 '[PawnPayments].[CreationTimeDate]) as MaxTransDate:"
I believe the error has to do with the bracket notation, but unfortunately, I am having to use this style due to a poorly constructed 3rd party table. Any help? Am I missing something obvious?
Huge EDIT: The table I am querying is actually on a SQL server, not a MySQL server! My database runs on the MySQL server, but this 3rd party database runs on an older version of Microsoft SQL.
I don't know why you have all those square brackets around your table and column names, but they aren't necessary and they aren't standard SQL. That's what is causing your syntax error.
my $SQLp = "SELECT MAX(PawnPayments.CreationTimeDate) as MaxTransDate
FROM PawnSafeDBCE.dbo.PawnPayments
INNER JOIN PawnSafeDBCE.dbo.PawnPaymentDetails
ON PawnPayments.PaymentID = PawnPaymentDetails.PaymentID
WHERE PawnPaymentDetails.TicketID = '$TicketID'
AND PawnPaymentDetails.StoreID ='$StoreID'";
I'll also add that having variables interpolated in your SQL statement like that is potentially leaving you open to SQL injection attacks. Far better to use bind points in your SQL and use extra arguments to execute to fill in the values (assuming you're using DBI).
my $SQLp = "SELECT MAX(PawnPayments.CreationTimeDate) as MaxTransDate
FROM PawnSafeDBCE.dbo.PawnPayments
INNER JOIN PawnSafeDBCE.dbo.PawnPaymentDetails
ON PawnPayments.PaymentID = PawnPaymentDetails.PaymentID
WHERE PawnPaymentDetails.TicketID = ?
AND PawnPaymentDetails.StoreID = ?";
my $sth = $dbh->prepare($SQLp);
$sth->execute($TicketID, $StoreID);
Update: As Bill Karwin points out in a comment, the database.schema.table syntax makes no sense in a MySQL database. So I think you're a little confused. The error message you are getting definitely mentions MySQL, so you're connecting to a MySQL server, using DBD::MySQL - but perhaps you should be connecting to an MSSQL server instead.
It might be useful if you showed us your database connection code - the call that sets up your $dbh (or equivalent) variable.
You say you are querying a MS SQL database, but the error message clearly says you are using a MySQL database or a MySQL database driver.
If you are querying a MS SQL database, fix your connection string.
If you are querying a MySQL database, use a MySQL-compatible query. MySQL uses backticks to quote identifiers (not square brackets like MS SQL).
[PawnPayments].[CreationTimeDate]
should be
`PawnPayments`.`CreationTimeDate`
Note that your code suffers from injection bugs due to incorrect quoting of value inserted into the SQL query. (It's not good enough just to put quotes around the values!) These can cause your code to fail, and they could make you vulnerable to injection attacks. Fix the quoting, or use replaceable parameters.
I use SQuirreL SQL client Version 3.5.3
I wanted to do an insert of a text with accent like éèà but I get a syntax error. The follow select statement doesn't work:
select 'élève';
The error is the following:
Error: Syntax error or access violation, message from server: "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 ''élèv' at line 1"
when I delete the é and è it works.
Does someone know how I can solve that accent problem ?
I just tried in my version of squirrel:
select 'élève' from dual;
Its on oracle. It worked without error. You probably need to make sure your connection is set up to handle unicode and that the underlying database supports that character set. Is that syntax even valid for your database? (I had to add "from dual" in order for it to become valid SQL).
I'm trying to search and replace in MYSQL but get an error. I'm quessing it's because of the "http://"
Anyone got any suggestions when trying replace this type of thing?
Code entered:
update movies_news set select_page = replace(select_page, ‘http://movie’, ‘http://www.movie’);
But it throws 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 '://movie’, ‘http://www.movie’)' at line 1
Posting so it can be accepted:
update movies_news set select_page = replace(select_page, ‘http://movie’, ‘http://www.movie’);
contains smart quotes, which are not interpreted as normal single quotes, thus the syntax error. It should instead be
update movies_news set select_page = replace(select_page, 'http://movie', 'http://www.movie');
In general, be really careful about copying code to and from 'smart' text editors (Microsoft Word, etc)
I'm using SQLAzureMW v3.8.8 but I get lots of errors in the script generated. And the problem is that i don't know in which line is each error generated.
Error #: 105 -- Unclosed quotation mark after the character string
'CREATE PROCEDURE [dbo].[spAdminParametrosGet]
Error #: 156 -- Incorrect syntax near the keyword 'ELSE'.
Error #: 40512 -- Deprecated feature 'NOLOCK or READUNCOMMITTED in
UPDATE or DELETE' is not supported in this version of SQL Server.
Incorrect syntax near '
The TSQL script generates sql stored procedures as strings and are created using dynamic SQL. Some stored procedures have comments inside of it.
May that be the cause or any suggestion to quickly migrate the database to Azure?
It is very much possible that some of the SP and other statements which you want to migrate from SQL Server to SQL Azure are not compatible. Here is a list of supported and unsupported TSQL features:
http://msdn.microsoft.com/en-us/library/windowsazure/ee336250.aspx
Also you haven't mentioned what is your source SQL Server is? As not all SQL Server will full features are supported by SAMQ (3.8 or 4.01)
Also please match your TSQL statements from the unsupported list below and check if any of listed below are part of your TSQL statements:
http://msdn.microsoft.com/en-us/library/windowsazure/ee336253.aspx
I am using EDMX with MySql 5.1. It is working fine except When I try to execute the lambda expression, it shows me the following 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 '[XYZ].[UserID] AS [UserID], [XYZ].[FirstName] A' at line 17
where [XYZ] is the table name and [UserID], [FirstName] are the columns of that table. Following is the statement, that I want to execute -
_context.XYZSet.Where(org => org.ACDID == sbuID || !(org.ACDID.HasValue)).ToList();
Please help..
I do not know anything about EDMX, but from that error it looks like it's using MS SQL Server syntax to escape table and column names, which is not supported by MySQL. MySQL uses backticks for that, not square brackets.
If you could get EDMX to stop escaping the table and columns names then you might be okay, assuming none of the table/column names are reserved words.