Problems with db:set

Post Reply
Kimos
Posts: 3
Joined: Sat May 01, 2010 10:05 am

Problems with db:set

Post by Kimos » Sat May 01, 2010 10:15 am

I'm having issues with db:set generating errors, and I'm smacking my head against my desk trying to figure out what it is, or even if it's a possible bug...

My code is as follows:

Code: Select all


crits = db:create("oxide_crits",
	{
		count = {
			type = "",
			count = 0,
			_unique = { "type" },
			_violations = "IGNORE",
		}
	}
)

function RegisterHit(type)
	echo("Counting hit: "..type)
	db:set(crits.count.count, db:exp("count + 1"), db:eq(crits.count.type, type))
end

function LoadDefaults()
	db:add(crits.count, 
		{ type = "normal", count = 0 },
		{ type = "CRITICAL", count = 0 },
		{ type = "CRUSHING CRITICAL", count = 0 },
		{ type = "OBLITERATING CRITICAL", count = 0 },
		{ type = "ANNIHILATINGLY POWERFUL CRITICAL", count = 0 },
		{ type = "WORLD-SHATTERING CRITICAL", count = 0 }
	)
end

-- We are ignoring unique key violations, so lets setup the default state here
oxide.crits:LoadDefaults()

Which all works fine till I try to call RegisterHit(). If I call, say, RegisterHit("normal"), I get the following error in my console:

Code: Select all

[ERROR:] object:<Hit trigger> function:<Trigger34>
<...Documents and Settings/***/.config/mudlet/db.lua:750: attempt to index global 'sheet' (a nil value)>
Which is the following code:

Code: Select all

function db:set(field, value, query)
   local db_name = sheet._db_name -- HERE
   local s_name = sheet._sht_name

   local conn = db.__conn[db_name]
Without knowing too much about the db module... should those first two lines be pointing at field instead?

Kimos
Posts: 3
Joined: Sat May 01, 2010 10:05 am

Re: Problems with db:set

Post by Kimos » Sat May 01, 2010 11:59 pm

I rewrote my RegisterHit function as the following and it all seems to be working now:

Code: Select all

function oxide.crits:RegisterHit(type)
	local curr = db:fetch(oxide.crits.db.count, db:eq(oxide.crits.db.count.type, type))[1]
	curr.count = curr.count + 1
	db:update(oxide.crits.db.count, curr)
end
Would be nice if someone could confirm whether the original post is a bug in mudlet or my code though... I'm running 1.1.0

ixokai
Posts: 63
Joined: Fri Dec 25, 2009 7:43 am

Re: Problems with db:set

Post by ixokai » Sun May 02, 2010 1:05 am

Yes, db:set introduced a bug in refactoring. Will make sure its fixed in the next release.

Kimos
Posts: 3
Joined: Sat May 01, 2010 10:05 am

Re: Problems with db:set

Post by Kimos » Sun May 02, 2010 4:51 am

Cheers Ixokai. Good to know I wasn't just going insane.

Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests