VFP 9 - MySql Error in SQL Syntax - mysql

Connecting from VFP 9 To MySql
lnTestForExisting=SQLEXEC(m.WorkingDatabase, "SELECT student_id, date_treated, where_treated, treatment, id AS CloudId ;
FROM medical WHERE school_id=?lcSchoolId AND downloaded_to_desktop!='Y'","StudentsMedFromServer")
Works Fine Data comes down just like it should then when I go to send the update back to the server using this
lnGoodServerUpdate=SQLEXEC(m.WorkingDatabase,"UPDATE SET medical downloaded_to_desktop='Y' WHERE SchoolId=?ServerSchoolId and id=?lnCloudId")
Generates syntax error and says the error is near the Where clause - the value in ?ServerSchoolId is reported as _lati (and then it cuts off I assume the word is _latin)
TIA

Related

Unknown Colum in Update Statement for Column that is not in query

I'm trying to update my table. My query is
'UPDATE mainOrderData SET isInvoiced = ?, invoiceCw = ? WHERE id = ?'
with params [1, "15", 17408]
That query is from Symfony / Doctrine. But I've already tried many variations of that, the error is not simply a typo or syntax error. It occurs no matter how I feed the sql into the database, it's something to do with the structure of the database.
I always get the error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'MainOrderId'
in 'where clause'
Now the curious thing is - I never specified MainOrderId. I specified id, and that column exists and is the right one.
How the hell does my database change that query?
Here's my server info:
MySQL
Server: Localhost via UNIX socket
Server Version: 5.5.59
Protokoll-Version: 10
Benutzer:
MySQL-Zeichensatz: UTF-8 Unicode (utf8)
Apache
MySQL-Client-Version: mysqlnd 5.0.11-dev - 20120503 - $Id: $
PHP Erweiterung: mysql
My code is pretty boilerplate:
$mainOrderData = $em->getRepository(MainOrderData::class)->find($id);
$woche = date("W");
$mainOrderData->isInvoiced = 1;
$mainOrderData->invoiceCw = $woche;
$em->flush();
I've no relations in the entities, and no triggers postupdate or somesuch defined. The entity in question does not hava a MainOrderId, only other entities that are not connected to the object manipulated.
The same thing happens if I use a manual sql query - any reference to id will be changed to MainOrderId.
This could happen if you have a trigger on the table. – Gordon Linoff 19 mins ago
That was it, the triggers were hidden and I had no idea they were there. The error message was unhelpful, too.
Thanks, Gordon Linoff!

how to delete a file with symbols (Specifically the apostrophe)

I have a database that stores teams. Each of these team names is unique. In the event that one is named Bob's Team. I have successfully managed to % encode the symbols when it is sent through the querystring to the next file. In this file I am getting an error with the SQL due to the apostrophe and I don't know how to fix it. Not quite sure about all this escaping stuff I'm reading. It's pretty confusing. Here is the line causing the problem:
strSQL = "SELECT * FROM Teams WHERE TeamName='" & TheTeamName & "'"
In the event that Bob's Team is the name of the team. The error I get is:
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'TeamName='Bob's Team''.
/DeleteTeam.asp, line 35
I'd like to know what I have to do in order to make it properly delete a team with an apostrophe (and possibly other annoying symbols) in it.
To make your query work as is you can try the following:
Replace in TheTeamName the Single Quote ' by ''
Then use it in your query. (#least this works in MySQL not sure abt your DB engine but give it a try).
Note that it is better to use prepared statement to prevent SQL-Injection

issues with Transient Attributes Using Groovy Expressions on MySQL db

I'm using JDevelper 11.1.2.4 and MySql DB 5.6.19. The version of JConnector I am using is mysql-connector-java-5.1.30-bin.
I've created two tables country and city.
In table city, there is foreign key to link it with the country table.
JDevelper have created associations and view links for these tables which I've tested using ADF Model Tester and they are looking fine.
I've created a transient column CountryName and set the default value (as Expression) to Country1.CountryName.
Now when I run the ADF Model Tester again, I get the following error:
(oracle.jbo.SQLStmtException) JBO-27122: SQL error during statement preparation.
Statement:
SELECT CountryEO.country_id, CountryEO.country_name, CountryEO.country_code,
CountryEO.country_short_name, CountryEO.currency_id, CountryEO.created_date,
CountryEO.created_by, CountryEO.last_updated_date, CountryEO.last_updated_by
FROM cms.country CountryEO WHERE CountryEO.country_id = ?
----- Level 1: Detail 0 -----
(com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException)
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
'OPTION SQL_SELECT_LIMIT=1' at line 1
What may be the problem?
Please check your country view object query by sql puls / toad etc. If its correct please post your question

Rails & MySQL: SELECT Statement Single vs. Double Quotes

I have a CRON job which executes a SELECT statement to grab records. When the SELECT runs on my dev machine, it produces the following statement:
SELECT `users`.* FROM `users` WHERE `users`.`id` = 87 LIMIT 1
This is successful.
When the SELECT runs on my production (hosted) machine it produces the statement with double quotes:
SELECT "users".* FROM "users" WHERE "users”.”id” = 87 LIMIT 1
This is not successful and I get a MySQL 1064 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 '.* FROM "users" WHERE "users
The code is the same on both machines, but my dev MySQL is version 5.5.33, whereas production is 5.1.67 (I don't have control over this to set/update it)
Is there a way to force single quotes or another preferred method to handle this situation?
Thanks for your time and assistance.
--EDIT--
Here are the main code snippets that are invoked via my CRON job:
/lib/tasks/reports.rake
namespace :report do
desc "Send Daily Report"
task :daily => :environment do
User.where(:report_daily => 1).find_each do |user|
ReportsMailer.send_report(user, 'daily').deliver
end
end
/app/mailers/reports_mailer.rb
def send_report(user, date_increment)
#user = user
#date_increment = date_increment
get_times(user)
mail :to => user.email, :subject=> "Report: #{#dates}"
end
--EDIT2--
So it looks like I need to use slanted single quotes (`) in order for this to work successfully. How do I force my app or MySQL to use these instead of double (") quotes?
I don't know why it does this, but I do know that if you're referencing column names in MYSQL, you need to use ``, whereas values / data should be wrapped in "", like this:
SELECT `users`.* FROM `users` WHERE `users`.`id` = "87" LIMIT 1
I learnt this the hard way back in the day when I was learning how to do simple MYSQL queries
Here's some documentation from MYSQL's site for you:
The identifier quote character is the backtick (“`”):
mysql> SELECT * FROM `select` WHERE `select`.id > 100;
Identifier quote characters can be included within an identifier if
you quote the identifier. If the character to be included within the
identifier is the same as that used to quote the identifier itself,
then you need to double the character. The following statement creates
a table named a`b that contains a column named c"d:
mysql> CREATE TABLE `a``b` (`c"d` INT);
Is there any reason you couldn't put some of your sql statement directly into your code like:
User.where("`report_daily`=1").find_each do |user|
After further inspection, and working with my hosting company, its turns out that my query is timing out on their server. Thanks to all that responded.
Since you are not using any literals, the format of the generated SQL statements should be determined by the underlying adapter. Perhaps you have a different mysql adapter installed or configured on each machine. Check the installed version. For example:
bundle show mysql
and also check the adapter configuration for your project in database.yml. For example:
adapter: mysql
A comparison of the results of these checks between each machine should tell you if you are using different adapters on the two machines.

MySQL - Data with the symbol "&"

I have the below data in my MySQL table "categories":
id Name
-----------------
1 Books & CDs
2 Dress
When I try to get the value from table it works fine with below SQL.
SELECT * FROM `categories` WHERE `name` = 'Books & Cds';
But when using in PHP, it gives me some SQL error.
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 '' at line 5
Where can I find the actual reason for this? How to debug this?
If you want to search for rows in your Category table in your PHP code, I recommend that you add a column in your table for a code to use instead of searching on the name that you use for the end users. The potential problem that you're facing is that if you want to change the name of a category, you'd have to find everywhere in your code that you referred to that category by name and change it too. But if your table looked like this:
ID code name
1 BCDS Books & CDs
2 DRS Dress
then your code can do things like "where code = 'BCDS'" and you can call that category "Books & CDs", "CDs and Books", or anything else you like.
Now, as far as fixing your syntax problem, you'll have to post the PHP that you use to generate the query that fails. As another poster said, you're probably escaping something incorrectly and MySQL isn't getting the query you think it's getting.