public function testGetTablesArray() { $tablename = 'test' . mt_rand(); $this->createTableParams($tablename, array('foo' => array('name' => 'foo', 'type' => 'varchar', 'len' => '255')), array()); $this->assertTrue($this->_db->tableExists($tablename)); $this->dropTableName($tablename); }
/** * Creates the custom table with an id of id_c. * * @param bool $execute * @return string */ public function createCustomTable($execute = true) { $out = ''; if (!$this->db->tableExists($this->bean->table_name . '_cstm')) { $GLOBALS['log']->debug('creating custom table for ' . $this->bean->table_name); $idDef = array('id_c' => array('name' => 'id_c', 'type' => 'id', 'required' => 1)); $idIdx = array('id' => array('name' => $this->bean->table_name . '_cstm_pk', 'type' => 'primary', 'fields' => array('id_c'))); $query = $this->db->createTableSQLParams($this->bean->table_name . '_cstm', $idDef, $idIdx); if (!$this->db->supports('inline_keys')) { $indicesArr = $this->db->getConstraintSql($idIdx, $this->bean->table_name . '_cstm'); } else { $indicesArr = array(); } if ($execute) { $this->db->query($query); if (!empty($indicesArr)) { foreach ($indicesArr as $idxq) { $this->db->query($idxq); } } } $out = $query . "\n"; if (!empty($indicesArr)) { $out .= implode("\n", $indicesArr) . "\n"; } $out .= $this->add_existing_custom_fields($execute); } return $out; }
/** * Delete the primary table for the module implementing the class. * If custom fields were added to this table/module, the custom table will be removed too, along with the cache * entries that define the custom fields. * */ function drop_tables() { global $dictionary; $key = $this->getObjectName(); if (!array_key_exists($key, $dictionary)) { $GLOBALS['log']->fatal("drop_tables: Metadata for table " . $this->table_name . " does not exist"); echo "meta data absent for table " . $this->table_name . "<br>\n"; } else { if (empty($this->table_name)) { return; } if ($this->db->tableExists($this->table_name)) { $this->db->dropTable($this); } if ($this->db->tableExists($this->table_name . '_cstm')) { $this->db->dropTableName($this->table_name . '_cstm'); DynamicField::deleteCache(); } if ($this->db->tableExists($this->get_audit_table_name())) { $this->db->dropTableName($this->get_audit_table_name()); } } }
/** * Check that DB settings are fine * @return bool */ protected function preflightDB() { $check = $this->db->canInstall(); if ($check !== true) { $error = array_shift($check); array_unshift($check, $this->translate($error)); return $this->error(call_user_func_array('sprintf', $check), true); } $tablename = "uptest" . uniqid(); if (!$this->db->query("CREATE TABLE {$tablename}(a int, b int)")) { $fail = "Table creation"; } elseif (!$this->db->query("INSERT INTO {$tablename}(a,b) VALUES(1,2)")) { $fail = "Insertion"; } elseif (!$this->db->query("UPDATE {$tablename} SET a=2 WHERE a=1")) { $fail = "Update"; } elseif (!$this->db->query("DELETE FROM {$tablename} WHERE a=2")) { $fail = "Deletion"; } if ($this->db->tableExists($tablename)) { if (!$this->db->query("DROP TABLE {$tablename}") && empty($fail)) { $fail = "Table deletion"; } } if (!empty($fail)) { return $this->error("{$fail} test failed, please check DB permissions.", true); } return true; }