Page 1 of 1

TMySQLServer

Posted: Fri Dec 07, 2018 4:25 pm
by serge_girard
Hello,

I need to know the number of rows that are inserted/updated/deleted. This function is called 'affected_rows' (in PHP- MySQL)
Apparantly it is missing in Harbour and now I managed to find out how, but still it doesn't work.

Code: Select all

cSQL := "DELETE FROM table WHERE something..."
cQuery	:= dbo:Query( cSQL )

nAFF     := dbo:affected_rows() 
? 'dbo:className', dbo:className()		-->TMYSQLSERVER INSTEAD OF TMy2SQLServer


CREATE CLASS TMy2SQLServer INHERIT TMySQLServer   
METHOD affected_rows()                       
ENDCLASS

METHOD affected_rows() CLASS TMy2SQLServer        
RETURN mysql_affected_rows( ::nSocket )
The 'new' function however always refers to TMYSQLSERVER instead of TMy2SQLServer.
My knowledge of Classes/Methods is poor. Someone knows whar or how to make it work?

Thx, Serge

Re: TMySQLServer

Posted: Fri Dec 07, 2018 4:33 pm
by susviela
Test:

SELECT ROW_COUNT();

https://stackoverflow.com/questions/430 ... -statement

-----------
OR

one way, not very optimal is to simply do a select before you do the update.

select count(*) from table1 where country = 'country1'

Re: TMySQLServer

Posted: Fri Dec 07, 2018 9:44 pm
by serge_girard
Thanks Susviela, that is exactly what I am doing now: count before, ask for confirmation, then execute or not.
After execution I do a select row_count to see if first count and row_count matches, if not something has changed in between... This works fine but I was wondering why the affected_rows method isn't working as it should.
I was told to change contrib\hbmysql\tmysql.prg but I cannot find this file in my hmg folders.

Serge

Re: TMySQLServer

Posted: Mon Dec 10, 2018 9:44 am
by vagblad
Serge,

Maybe it is silly to ask this but did you instantiate the dbo object like this?
dbo := TMy2SQLServer():New(cServer,cUsername,cPassword,nPort)

Re: TMySQLServer

Posted: Mon Dec 10, 2018 1:26 pm
by serge_girard
Hello Vagelis,

No, I did not!

I now tried and it works..!
Brilliant thinking Vagelis !

Thank you so much,

Serge