Skip to content

Commit

Permalink
fixed the varchar prim key bug plus added .... to query
Browse files Browse the repository at this point in the history
  • Loading branch information
DeathGOD7 committed Apr 13, 2024
1 parent 3066536 commit 5f99e12
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private Connection connectMySQL() {
config.setJdbcUrl("jdbc:mysql://" + cleanedUrl + "/" + this.dbName);
config.setUsername(this.username);
config.setPassword(this.password);
config.setDriverClassName("com.mysql.cj.jdbc.Driver");
//config.setDriverClassName("com.mysql.cj.jdbc.Driver");
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
Expand Down Expand Up @@ -115,7 +115,7 @@ public void loadMysqlTables() {
}
public Table loadTable(String tablename) {
// query all the column name and its type
String query = "SHOW COLUMNS FROM " + tablename + ";";
String query = "SHOW COLUMNS FROM `" + tablename + "`;";
LinkedHashMap<String, Column> columns = new LinkedHashMap<>();
String primarykey = "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ public void loadSqliteTables() {
// sqlite based querys
public Table loadTable(String tablename) {
// query all the column name and its type
String query = "SELECT * FROM pragma_table_info('" + tablename +"');";
// String query = "SELECT * FROM pragma_table_info('" + tablename +"');";
String query = "PRAGMA table_info(`" + tablename + "`);";
LinkedHashMap<String, Column> columns = new LinkedHashMap<>();
String primarykey = "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public boolean createTable(Table table, DatabaseType dbtype) {
// primary key columns
query.append("`").append(table.getPrimaryKey().getName()).append("` ");
query.append(this.parseInputDataType(table.getPrimaryKey().getDataType()));
query.append(table.getPrimaryKey().getLimit() > 0 ? " (" + table.getPrimaryKey().getLimit() + ")" : "");
query.append(" PRIMARY KEY");
if (dbtype == DatabaseType.SQLite && table.getPrimaryKey().isAutoIncrement()) {
query.append(" AUTOINCREMENT");
Expand All @@ -125,8 +126,8 @@ else if (dbtype == DatabaseType.MySQL && table.getPrimaryKey().isAutoIncrement()
for (Column column : table.getColumns()) {
query.append("`").append(column.getName()).append("` ");
query.append(this.parseInputDataType(column.getDataType()));
query.append(column.getLimit() > 0 ? " (" + column.getLimit() + ") " : "");
query.append(column.getDefaultValue() != null ? " DEFAULT '" + column.getDefaultValue() + "' " : "");
query.append(column.getLimit() > 0 ? " (" + column.getLimit() + ")" : "");
query.append(column.getDefaultValue() != null ? " DEFAULT '" + column.getDefaultValue() + "'" : "");
query.append(!column.isNullable() ? " NOT NULL, " : ", ");
}
// end closing
Expand Down

0 comments on commit 5f99e12

Please sign in to comment.