SQL Update returning zero rows - mysql

UPDATE starfsfolk
SET starfsfolk.stada=2
WHERE starfsfolk.deild LIKE '%Hugbúnaðardeild%';
UPDATE starfsfolk
SET starfsfolk.stada=3
WHERE starfsfolk.deild LIKE '%Markaðsdeild%'
is prescisely the code i'm using.
i've tried various different versions of it(like = "Markaðsdeild" or LIKE "Markaðsdeild")
most of which work if i'm using select, but i needed to use update and its not working for some reason.
This WHERE command works on select but
it returns zero rows if i'm using the update command. What am i doing wrong?
Edit:
Just to clarify, stada is set to 1 in all cases before and after the update command. it hasn't changed from 1 to 2 and 3 like i wanted it to.
Edit2: heres a screenshot of the database, i could also give you the create commands.
Edit3: Stada is bit, not int, i found out, not sure what that changes tho.
Solution: Solved myself, since bit is just 1 and 0, the error was in the creation of the table so i remade it with stada as int and now the code is working.

If the value of stada is not changed by the query then zero rows will be returned because nothing was updated.

The character sets of the server and of the client are different.
http://dev.mysql.com/doc/refman/5.5/en/charset-connection.html

Related

Know the result of 'insertIgnore' with Jetbrains Exposed

I'm using Jetbrains Exposed to interact with my MySQL 5.7 database.
The problem I have is with insertIgnore.
As I see it, there is no way of knowing the result of the statement. MySQL itself will return either 1 if a row was inserted, or 0 if it was ignored because of an error (in my case, duplicate key error).
But I can't see any way to see that from the result of the insert.
My code is basically just:
transaction(database) {
MyTable.insertIgnore {
it[uniqueColumn] = "foo"
}
}
Executed twice where uniqueColumn is unique. There is no difference in the results, although the first time is successful and the second time isn't.
It seems like an easy thing to have the resulted rows of that statement be represented somewhere, but I couldn't find anything myself or when googling.
I had a similar problem and I solved it using IntIdTable instead of Table
And insertIgnoreAndGetId instead of insertIgnore
Maybe it will help anyone

updating 2 fields in mysql (with one update being null update)

I'm basically trying to do this:
update <table> set process_flg='N' where id<1201;
update <table> set time_stamp=null where id<1201;
this works fine if I use 2 different updates.
but, if I compress them to be:
update <table> set process_flg='N' and time_stamp=null where id<1201;
it just doesn't work.
the time_stamp remains the value it was while process_flg becomes 0.
I see your your compressed query and there is mistake. Your compressed query should be like below:
UPDATE SET process_flg='N', time_stamp=null WHERE id<1201;
You need to use "," instead of "and" statement.
Please take a look here more information:
http://www.w3schools.com/sql/sql_update.asp

CONVERT_TZ not working

We have a script to run through PHP myAdmin, as follows:
UPDATE utilities_alert SET date=CONVERT_TZ(date,'-06:00','00:00');
UPDATE utilities_update SET date=CONVERT_TZ(date,'-06:00','00:00');
UPDATE utilities_assetlocation SET start=CONVERT_TZ(start,'-06:00','00:00');
UPDATE utilities_assetlocation SET end=CONVERT_TZ(end,'-06:00','00:00');
UPDATE utilities_idlelog SET date=CONVERT_TZ(date,'-06:00','00:00');
It's not working and returning NULL values. Then I came across this
http://www.geeksengine.com/article/populate-time-zone-data-for-mysql.html
, followed all the steps and to no avail.
There may well be a bug in this verb, I spent some time getting very frustrated trying this. However I did get it to work if I used this format.
SELECT CONVERT_TZ(TimeSeen, 'America/New_York','Europe/London');
Where TimeSeen was a DateTime field.
If you have loaded the timezone data as you say, it should work.
The issue was that I forgot a + sign.
It should be:
UPDATE utilities_alert SET date=CONVERT_TZ(date,'-06:00','+00:00');
UPDATE utilities_update SET date=CONVERT_TZ(date,'-06:00','+00:00');
UPDATE utilities_assetlocation SET start=CONVERT_TZ(start,'-06:00','+00:00');
UPDATE utilities_assetlocation SET end=CONVERT_TZ(end,'-06:00','+00:00');
UPDATE utilities_idlelog SET date=CONVERT_TZ(date,'-06:00','+00:00');

count(*) on mysql giving me value 0

select count(*) FROM antecedente_delito WHERE rut_polichile = NEW.rut_polichile
this statement is giving de value 0, when it should give me 18 :/ ive been trying a lot to find any bug in it.
Here's the working solution that I mocked up using/changing your code in SqlFiddle. http://sqlfiddle.com/#!2/ac2e9/1
To trouble shoot this, I would view your actual values and verify that NEW. is returning what you think it should. Sometimes it may be doing some trims or removal of special characters, especially the _ and % signs are likely to stripped in subprocedures.
I would start with the query:
select top 50 rut_polichile, NEW.rut_plichile FROM antecedente_delito
If the issue is not obvious from that add in a varbinary check:
select top 50 cast( rut_polichile as varbinary), cast(NEW.rut_plichile as varbinary) from antecedente_delito
If the table only has 18 records, then you should be good to go with the above troubleshooting, but if there is more data, I would suggest limiting your results from the above by the rowid or other identifier in a where statement.
It's not the answer, but I hope it helps you find the answer.
The SELECT privilege for the subject table if references to table columns occur via OLD.col_name or NEW.col_name in the trigger definition.
but in your trigger i can't see any trigger definition. so try without NEW.
for more info: http://www.sqlinfo.net/mysqldocs/v51/triggers.html or
http://bugs.mysql.com/bug.php?id=31068

How do i get this IF statement to work in MYSQL (it's in a stored procedure)?

I can't find an example anywhere that doesn't give me syntax errors
My code is
BEGIN
UPDATE Room_Descriptions
IF(STRCMP(Bed_Type,'King')) THEN SET Max_People = Number_Beds * 3
END
Basically it's supposed to go through the table and look at the column "Bed_Type", if it finds the word "King" it'll multiply that row's Number_Beds by 3 and set that in the column Max_People
I was hoping to eventually get some if elses going on but I'll settle for just one if that works.
UPDATE Room_Descriptions SET Max_People = Number_Beds*3 WHERE STRCMP(Bed_Type,'King')
All it takes is a conditional UPDATE.