Archive > BeBot Hyborian support

Support for a prefix in the tablenames

(1/1)

Alreadythere:
As I'm seeing some modules using fixed tablenames here a short introduction how to use the support for a prefix in tablenames offered by the BeBot core.

In the CREATE call don't use a fixed tablename, instead use the $this->bot->db->define_tablename($tablename, $prefix) function.
The variable $tablename is a string containing the name of the table, without any prefix. This name without prefix is called internal name in the following.
The variable $prefix is a boolean (or string containing "true" or "false") defining whether the bot should use a prefix for this tablename on default (true/"true") or not (false/"false").

In any other SQL queries to this table use the internal name prefixed with #___ (# followed by 3 _) as prefix. The MySQL module will convert all those tablenames based on the entries for the internal name to use a prefix or not as defined.

The following is a simple example of some code using this ability:

--- Code: ---$this->bot->db->query("CREATE TABLE " . $this->bot->db->define_tablename("test_table", "true") . " (id INT)");
$this->bot->db->query("INSERT INTO #___test_table (id) VALUES (123)");
$this->bot->db->select("SELECT nickname FROM #___whois WHERE id IN (SELECT id FROM #___test_table)");
--- End code ---

Navigation

[0] Message Index

Go to full version