return self::e($sql, $param);
}
+ /**
+ * @brief Locks a table for exclusive write access
+ *
+ * This function can be extended in the future to accept a table array as well.
+ *
+ * @param string $table Table name
+ *
+ * @return boolean was the lock successful?
+ */
+ static public function lock($table) {
+ return self::e("LOCK TABLES `".self::$dbo->escape($table)."` WRITE");
+ }
+
+ /**
+ * @brief Unlocks all locked tables
+ *
+ * @return boolean was the unlock successful?
+ */
+ static public function unlock() {
+ return self::e("UNLOCK TABLES");
+ }
+
/**
* @brief Starts a transaction
*
$start = time();
do {
- dba::p("LOCK TABLE `locks` WRITE");
+ dba::lock('locks');
$lock = dba::select('locks', array('locked', 'pid'), array('name' => $fn_name), array('limit' => 1));
if (dbm::is_result($lock)) {
$got_lock = true;
}
- dba::p("UNLOCK TABLES");
+ dba::unlock();
if (!$got_lock) {
sleep($wait_sec);