|
Quit Wanderer
Joined: 19 Jul 2008 Posts: 59
|
Posted: Sun Mar 04, 2012 10:14 pm
Sql Error |
Hi
Why do I get this error: SQL Error: MySQL server has gone away.
I can connect to my server with other programs, so nothing wrong with the server.
If I close and reopen Cmud its all ok and every thing works. |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Sun Mar 04, 2012 11:33 pm |
Did you make any changes to the DB structure while CMud was connected to it? Even though you CAN do this, you're not supposed to and typically any connections in effect after you make those changes will break the next time they are used to access the DB.
|
|
_________________ EDIT: I didn't like my old signature |
|
|
|
Quit Wanderer
Joined: 19 Jul 2008 Posts: 59
|
Posted: Mon Mar 05, 2012 7:10 pm |
I think its only happen when I wake my computer from sleep.
But I found something else.
When I run this, it put the data in the server, but if I keep running this with the same data, it keeps putting the data in
so I got more rows with the same data, think I need to do -update- the server or something ?
Code: |
db = %sqldb("database", "aardwolf", "mysql", "qnap" ,"xxx")
#CALL @db.Open
row = %sql(database, "SELECT * FROM mobs WHERE mobname= '@questmobname' AND zonename= '@questmobzone'")
#SHOW @row.RecordCount
#IF (@row.RecordCount = 0) {
update=%concat("INSERT INTO mobs (mylevel, mobname, zonename, zonenum, roomname, roomnum) VALUES ('"%gmcp.char.status.level"', '"%gmcp.comm.quest.targ"', '"%remove("The ",%gmcp.comm.quest.area)"', '"%zonenum()"', '"%gmcp.comm.quest.room"', '"%roomnum()"');")
#CALL @db.Execute(@update) } {
#WHILE (!@row.Eof()) {
#SHOW Room: @row.Item("roomname")
#CALL @row.Next}
}
#CALL @db.Close
|
|
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Tue Mar 06, 2012 12:55 am |
INSERT is for making new records, UPDATE is for changing existing ones. Dunno if MySQL has a reference website specific to it, but for the generic SQL you can check out w3schools.com for awesome tutorials.
|
|
_________________ EDIT: I didn't like my old signature |
|
|
|
Quit Wanderer
Joined: 19 Jul 2008 Posts: 59
|
Posted: Tue Mar 06, 2012 8:45 am |
I know the UPDATE command.
But my script open a connection, check to see if the name and zone exits,
if NOT, then INSERT new data and the close the connection.
But its like, it keeps the connection open so it does not see the change to the server,
and I can keep INSERT the same data
I do believe that a new connection should work like a refresh of the server.
I also use a program called HeidiSQL and here I can see if I press the refresh button
it reconnect to the server.
So I do think that #CALL @db.Close does not work. |
|
|
|
hogarius Adept
Joined: 29 Jan 2003 Posts: 221 Location: islands.genesismuds.org
|
Posted: Tue Mar 06, 2012 12:33 pm |
Does the #SHOW @row.RecordCount line ever show a value that is not 0?
Try entering a line #CALL db.Refresh immediately after the #CALL db.Open line. |
|
|
|
Quit Wanderer
Joined: 19 Jul 2008 Posts: 59
|
Posted: Tue Mar 06, 2012 2:39 pm |
no the @row.RecordCount stay on 0, but it do change if it find old data.
#CALL @db.Refresh give a error: No method/property: Refresh |
|
|
|
Quit Wanderer
Joined: 19 Jul 2008 Posts: 59
|
Posted: Tue Mar 13, 2012 9:13 pm |
Finally I got it to work
here is the code if it can help anyone:
Code: |
lkname = %subregex( {%1}, "'", "\'")
lklevel = {%2}
lkzone = %subregex( {%4}, "'", "\'")
lkroom = %subregex( %gmcp.room.info.name, "'", "\'")
lkroomnum = %gmcp.room.info.num
db = %sqldb( "database", "aardwolf", "mysql", "qnap" , "XXXX")
#CALL @db.Open
row = %sql( database, "SELECT * FROM lastkill WHERE name='"@lkname"' AND zone='"@lkzone"'")
#IF (@row.RecordCount = 0) {
#CALL @row.Edit
row.Item("name") = @lkname
row.Item("level") = @lklevel
row.Item("zone") = @lkzone
row.Item("room") = @lkroom
row.Item("vnum") = @lkroomnum
#CALL @row.post
#CALL @db.Close
} |
|
|
|
|
|
|