Clean method DDLCreateTable (used by modulebuilder only) #28996

This commit is contained in:
Laurent Destailleur
2024-03-21 12:10:09 +01:00
parent ae10eedf2a
commit ce2959b022
4 changed files with 117 additions and 80 deletions

View File

@@ -1288,12 +1288,12 @@ function createNewDictionnary($modulename, $file, $namedic, $dictionnaires = nul
}
$columns = array(
'rowid' => array('type' => 'integer(11)'),
'code' => array('type' => 'varchar(255) NOT NULL'),
'label' => array('type' => 'varchar(255) NOT NULL'),
'position' => array('type' => 'integer(11) NULL'),
'use_default' => array('type' => 'varchar(255) DEFAULT 1'),
'active' => array('type' => 'integer')
'rowid' => array('type' => 'integer', 'value' => 11),
'code' => array('type' => 'varchar', 'value' => 255, 'null'=>'NOT NULL'),
'label' => array('type' => 'varchar', 'value' => 255, 'null'=>'NOT NULL'),
'position' => array('type' => 'integer', 'value' => 11, 'null'=>'NULL'),
'use_default' => array('type' => 'varchar', 'value' => 11, 'default'=>'1'),
'active' => array('type' => 'integer', 'value' => 3)
);
@@ -1309,13 +1309,13 @@ function createNewDictionnary($modulename, $file, $namedic, $dictionnaires = nul
}
}
// check if tablename exist in Database and create it if not
$query = "SHOW TABLES LIKE '" . MAIN_DB_PREFIX.strtolower($namedic) . "'";
$query = "SHOW TABLES LIKE '" . $db->sanitize(MAIN_DB_PREFIX.strtolower($namedic)) . "'";
$checkTable = $db->query($query);
if ($checkTable && $db->num_rows($checkTable) > 0) {
setEventMessages($langs->trans("ErrorTableExist", $namedic), null, 'errors');
return;
} else {
$_results = $db->DDLCreateTable(MAIN_DB_PREFIX.strtolower($namedic), $columns, $primaryKey, "InnoDB");
$_results = $db->DDLCreateTable(MAIN_DB_PREFIX.strtolower($namedic), $columns, $primaryKey, "");
if ($_results < 0) {
dol_print_error($db);
$langs->load("errors");