1: <?php
2:
3: namespace Budabot\Core\Modules;
4:
5: use Budabot\Core\SQLException;
6:
7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30:
31: class SQLController {
32:
33: 34: 35: 36:
37: public $moduleName;
38:
39:
40: public $accessManager;
41:
42:
43: public $db;
44:
45:
46: public $commandManager;
47:
48:
49: public $text;
50:
51: 52: 53: 54:
55: public function setup() {
56:
57: }
58:
59: 60: 61: 62:
63: public function executesqlCommand($message, $channel, $sender, $sendto, $args) {
64: $sql = htmlspecialchars_decode($args[1]);
65:
66: try {
67: $num_rows = $this->db->exec($sql);
68: $msg = "$num_rows rows affected.";
69: } catch (SQLException $e) {
70: $msg = $this->text->makeBlob("SQL Error", $e->getMessage());
71: }
72: $sendto->reply($msg);
73: }
74:
75: 76: 77: 78:
79: public function querysqlCommand($message, $channel, $sender, $sendto, $args) {
80: $sql = htmlspecialchars_decode($args[1]);
81:
82: try {
83: $data = $this->db->query($sql);
84: $count = count($data);
85:
86: $msg = $this->text->makeBlob("Results ($count)", print_r($data, true));
87: } catch (SQLException $e) {
88: $msg = $this->text->makeBlob("SQL Error", $e->getMessage());
89: }
90: $sendto->reply($msg);
91: }
92:
93: 94: 95: 96:
97: public function loadsqlCommand($message, $channel, $sender, $sendto, $args) {
98: $module = strtoupper($args[1]);
99: $name = strtolower($args[2]);
100:
101: $this->db->beginTransaction();
102:
103: $msg = $this->db->loadSQLFile($module, $name, true);
104:
105: $this->db->commit();
106:
107: $sendto->reply($msg);
108: }
109: }
110: