 			callback error
 			return
 		else
-			dbConnection.query 'UPDATE `uniusers` SET `sessid` = ? WHERE `sessid` = ?',
+			dbConnection.query 'UPDATE uniusers SET sessid = $1 WHERE sessid = $2',
 				[ newSessid, sessid ], callback
 
 

# Get user id using his sessid.
# Returns a number, or an error.
exports.idBySession = (dbConnection, sess, callback) ->
	dbConnection.query "SELECT `id` FROM `uniusers` WHERE `sessid` = ?", [sess], (error, result) ->
		if result? and result.rowCount is 0
			error = "Wrong user's id"
		callback error, error or result.rows[0].id



# - userid,
#
# or an error.
exports.sessionInfoRefreshing = ((dbConnection, sessid, sess_timeexpire, asyncUpdate, callback) ->
	unless sessid?
		return sessionIsActive: false
	userdata = dbConnection.query.sync(dbConnection,
		"SELECT id, username, permissions FROM uniusers "+
		"WHERE sessid = $1 AND sess_time > NOW() - $2 * INTERVAL '1 SECOND'",
		[sessid, sess_timeexpire]
	)

	if userdata.rows.length is 0
		return sessionIsActive: false

	if asyncUpdate is true
		process.nextTick ->
			dbConnection.query(
				'UPDATE uniusers SET sess_time = NOW() WHERE id = $1',
				[userdata.rows[0].id],
				(error, result) ->
					if error?
						console.log 'Async update failed'
						console.log error.stack
			)
	else
		dbConnection.query.sync(dbConnection,
			'UPDATE uniusers SET sess_time = NOW() WHERE id = $1',
			[userdata.rows[0].id]
		)

	return {
		sessionIsActive: true
		username: userdata.rows[0].username
		admin: (userdata.rows[0].permissions is 'admin')
		userid: userdata.rows[0].id
	}
).async()


# Generate an unique sessid with the given length.
