Lisätty kuljetustietokantaan tyyppi sarake, sekä siistitty tietokannan alustamista

Signed-off-by: laurimaaninka <lauri.maaninka@gmail.com>
This commit is contained in:
2026-05-29 23:30:14 +03:00
parent 1042d3e41b
commit e4943d846c
2 changed files with 18 additions and 18 deletions
@@ -24,26 +24,19 @@ public class Tietokanta {
osoite = "jdbc:sqlite:" + tietokantatiedosto.getAbsolutePath(); osoite = "jdbc:sqlite:" + tietokantatiedosto.getAbsolutePath();
String sql = "";
try (Connection conn = haeYhteys()) { try (BufferedReader br = new BufferedReader(
InputStream is = Objects.requireNonNull(Main.class.getClassLoader().getResourceAsStream("tietokanta.sql")); new InputStreamReader(
BufferedReader br = new BufferedReader(new InputStreamReader(is)); Objects.requireNonNull(Main.class.getClassLoader()
String sql = br.readAllAsString(); .getResourceAsStream("tietokanta.sql"))))) {
sql = br.readAllAsString();
for (String query : sql.split(";")) { } catch (IOException e) {
conn.createStatement().execute(query); throw new RuntimeException(e);
}
}
catch (SQLException | IOException e) {
handleException(e);
} }
//Lisää kuljetuspäivät asiakassarakkeeseen (v2.0.2->3.x.x) for (String query : sql.split(";")) {
String[] sarakkeet = {"lauantaiKpl", "sunnuntaiKpl"};
for (String sarake : sarakkeet) {
try (Connection conn = haeYhteys()) { try (Connection conn = haeYhteys()) {
PreparedStatement stmt = conn.prepareStatement("alter table asiakkaat add column " + sarake + " int not null default 0"); conn.createStatement().execute(query);
stmt.execute();
} catch (SQLException e) { } catch (SQLException e) {
if (!e.getMessage().contains("duplicate column name")) { if (!e.getMessage().contains("duplicate column name")) {
handleException(e); handleException(e);
+8 -1
View File
@@ -40,4 +40,11 @@ create table if not exists kuljetukset (
lisätieto varchar(255) lisätieto varchar(255)
); );
create index if not exists idx_kuljetuspvm on kuljetukset(kuljetusPäivämäärä); create index if not exists idx_kuljetuspvm on kuljetukset(kuljetusPäivämäärä);
--2.0.2->3.x.x
alter table asiakkaat add lauantaiKpl int not null default 0;
alter table asiakkaat add sunnuntaiKpl int not null default 0;
--3.x.x->4.0.0
alter table kuljetukset add tyyppi varchar(50);