working on dropping old mails
This commit is contained in:
@@ -11,6 +11,7 @@ import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
|
||||
import static de.srsoftware.widerhall.Util.t;
|
||||
import static de.srsoftware.widerhall.data.MailingList.HOLD_TIME;
|
||||
|
||||
/**
|
||||
* @author Stephan Richter, 2022
|
||||
@@ -280,9 +281,30 @@ public class Database {
|
||||
if (!tableExists(MailingList.TABLE_NAME)) MailingList.createTable();
|
||||
if (!tableExists(ListMember.TABLE_NAME)) ListMember.createTable();
|
||||
if (!tableExists(Post.TABLE_NAME)) Post.createTable();
|
||||
if (!columnExists(MailingList.TABLE_NAME,HOLD_TIME)) MailingList.createHoldTimeColumn();
|
||||
return this;
|
||||
}
|
||||
|
||||
private boolean columnExists(String tableName, String columnName) throws SQLException {
|
||||
var rs = Database.open().select("pragma_table_info('"+tableName+"')","COUNT(*) AS num").where("name",columnName).compile().exec();
|
||||
try {
|
||||
if (rs.next()) return rs.getInt("num") > 0;
|
||||
} finally {
|
||||
rs.close();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void createColumn(String tableName, String colName, String...typeArgs) throws SQLException {
|
||||
var sql = new StringBuilder("ALTER TABLE ")
|
||||
.append(tableName)
|
||||
.append(" ADD COLUMN ")
|
||||
.append(colName)
|
||||
.append(" ")
|
||||
.append(String.join(" ",typeArgs));
|
||||
new Request(sql).compile().run();
|
||||
}
|
||||
|
||||
/**
|
||||
* prepare a deletion statement
|
||||
* @param tableName
|
||||
|
||||
Reference in New Issue
Block a user