Assistance with MySQL 'LIKE' Statement - mysql

Hello all you beautiful people,
To preface my question, we have a database that stores the entire HTML code of a web form (don't ask, I didn't create this) and some of those HTML values are populated from a different table. This table was discovered to have some double quotes (") in them, this is problem because if you have:
<input type="text" value="Hello "John" Smith">
It will break all of the tags below it.
We've gone ahead and fixed this, and I've implemented a solution to catch these from today onward. But now we have an unknown amount of forms that are broken.
So what I am trying to do is run an SQL statement to find all of the instances that this occurred.
Here is what I've got:
SELECT * FROM tableName WHERE data LIKE '%value="%"%"'
But this statement hasn't yielded any results.
Any help would be greatly appreciated!
Thank you,
DM

Your tags probably don't end with a quote, so let's add a wildcard at the end:
SELECT * FROM tableName WHERE data LIKE '%value="%"%"%'

If the value attribute is the last attribute in an element you could check if the value of value if enclosed in double quotes in this way:
SELECT * FROM tableName WHERE data
LIKE '%value="%"_%>'
The condition checks if there is double quote, before attribute value ends meaning incorrect value.
_% means one or more of any character.

Related

SELECT Showing me a list with the name of the column and not the data inside

I have quite a strange problem, I'm very new to SQL and I was doing a free course in SQL
I'm actually learning the "SELECT" command.
So, I create my database, create some table, put some data in it with the "INSERT INTO" command
And now I want to select some data in it, but I have a strange bug (not an error) when i do
SELECT * FROM aliment;
everything work like it's supposed to do, but when I do
SELECT 'nom','calories' FROM aliment;
Something strange happens.
Instead have a list of all the specific data i'm looking to get i just get a list with all the data replaced by the name of the columns.
Here 2 screen to show you what's happens:
[2
I know one it's from the terminal(and yes it's not mine but from a video) and mine is from the software, but it's still had to work no?
You have a typo in your SQL. Use backticks (on the same key as ~ on a US keyboard) around your column names, not '. Using a single quote (an apostrophe) makes it a literal value, not a column name.
SELECT `nom`,`calories`FROM aliment;

Syntax error in date in query expression for non-date fields

I'm having trouble building a query in Access 2013. The database isn't mine and the only thing I really have control over is this query. There is a table, I'm pulling 7 fields from it and eventually adding an 8th field to the query to do some string manipulation.
However, I keep getting getting "Syntax error in date in query expression 'fieldname'." error whenever I click on the arrow to sort the fields. The odd thing is these errors pop up when sorting non-date fields. When sorting the date field I get "Syntax error (missing operator) in query expression 'Release Date'."
This happens after a fresh build. I have no WHERE conditions, just SELECT and FROM. Ideas?
Here's the sql query, though I'm mainly working in the query design view:
SELECT Transmissions.[Job#], Transmissions.[Part#], Transmissions.TransmissionSN, Transmissions.Status, Transmissions.[Release Date], Transmissions.[Build Book Printed], Transmissions.[ID Tags Required]
FROM Transmissions;
Well... it seems you are the lucky inheritor of a poorly designed database.
Using special characters in a field name is just asking for trouble. And you've found what that trouble is.
Access uses the # sign to designate a Date type for query comparisons. Such as:
dtSomeDate = #2/20/2017#
You surround the date with the # signs.
In your case, the query thinks [Job#] and [Part#] are trying to wrap dates. But of course, that's not the case and thus it fails.
You can try a couple of work arounds. (I leave it to you to experiment.)
1) You can try to rename the problem fields within your query. So that:
Transmissions.[Job#] becomes Transmissions.[Job#] as JobNum
and
Transmissions.[Part#] becomes Transmissions.[Part#] as PartNum
2) You can try to copy the [Transmissions] table to a new table that you create
that does not have the naming problems.
3) Export the [Transmissions] table to a CSV file and re-import it to a new
table (or possibly new database) without the naming problems.
Here is a link to a microsoft article that tells you why to avoid special characters in Access:
Big Bad Special Chars.
Hope that puts you on the right track. :)
Typically, this means that the field names are missing or misspelled.
Try running this to see:
SELECT * FROM Transmissions;

How to query for the 'other' double quotes

I converted a large amount of data from mssql to mysql and a few of them came in with the 'other' double quotes ... the sharper ones.
I would like to do a query in phpmyadmin for all the entries that have that symbol because its breaking my query (coming back as null) but cannot figure out how to write it ...
SELECT * FROM table where id LIKE '%&#32%' <-- i dont actually know what the ascii symbol is for that one and this html ascii convention doesnt work anyway.
If you find one of them, can't you just copy it and paste it into your LIKE clause? That will prevent you from having to figure out the ASCII code for it.

Hyphen in fieldname causes INSERT statement in MS-Access to fail

I've been given an MS-Access application to maintain and being more acquainted with Oracle as dbms I bump into issues now and then..
Today it looks like MS-Access has problems when a hyphen is used for a column name...
The following insert statement was coupled to the NotInList event to add an extra entry to a listbox.
INSERT INTO tblProductInfo ( ProductInfo-Product )
"SELECT """ & NewData & """ AS ProductInfo-Product;"
But it's not working (anymore? first time the issue is reported, not sure if the original developer tested it out).
I've tested it out with a single-record append query and it looks like the hyphen is the culprit and I just cannot find a way to escape that..
INSERT INTO tblProductInfo ( ProductInfo-Product ) VALUES ("myData")
The error given is "Syntax error in INSERT INTO statement"
There does not seem any other way to specify the MS-Access fieldname, is it? (square brackets are only used for SELECT statements,
So... I'm calling for the wisdom of the Stackoverflow gods and am hoping someone knows how to solve this...
Thanks in advance !!
You need square brackets on that:
"INSERT INTO tblProductInfo ([ProductInfo-Product]) Values (""" & NewData & """)"
Or better yet, avoid odd characters and spaces in field and table names.
Square brackets are used in any sql statement where the field or table name is problematical:
It is a reserved word
It contains a space
It includes a special character
You can even use them with DDL:
Create Table tblProductInfo ( [ProductInfo-Product] Text(50))

PHP/MYSQL match against query

I am trying to run a match against query and it is not working. I created a full text index on the two fields. But am getting sql error right before word 'relationship". Here is sql:
"SELECT * FROM pages WHERE MATCH (shdescript,ldescript) AGAINST (romance, relationship)";
I have also tried just searching against shdescript and just searching against ldescript but get same error. Also I've tried searchstring without spaces. As far as I know, you are supposed to have the words of the searchstring separated by commas in parentheses. What am I doing wrong? Thanks.
Add quotes around your search string.
"SELECT * FROM pages WHERE MATCH (shdescript,ldescript) AGAINST ('romance', 'relationship')";
Also make sure you protect yourself against the nasty SQL injection threat, read more here.
Try quoting your string (i.e 'romance' and 'relationship')
SELECT * FROM pages WHERE MATCH (shdescript,ldescript) AGAINST ('romance', 'relationship')
I believe your AGAINST must be in quotes. From:
http://dev.mysql.com/doc/refman/4.1/en/fulltext-search.html#function_match
AGAINST takes a string to search for, and an optional modifier that
indicates what type of search to perform. The search string must be a
literal string, not a variable or a column name.