Lisätty kuljetustietokantaan tyyppi sarake, sekä siistitty tietokannan alustamista
Signed-off-by: laurimaaninka <lauri.maaninka@gmail.com>
This commit is contained in:
@@ -24,26 +24,19 @@ public class Tietokanta {
|
||||
|
||||
osoite = "jdbc:sqlite:" + tietokantatiedosto.getAbsolutePath();
|
||||
|
||||
|
||||
try (Connection conn = haeYhteys()) {
|
||||
InputStream is = Objects.requireNonNull(Main.class.getClassLoader().getResourceAsStream("tietokanta.sql"));
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(is));
|
||||
String sql = br.readAllAsString();
|
||||
|
||||
for (String query : sql.split(";")) {
|
||||
conn.createStatement().execute(query);
|
||||
}
|
||||
}
|
||||
catch (SQLException | IOException e) {
|
||||
handleException(e);
|
||||
String sql = "";
|
||||
try (BufferedReader br = new BufferedReader(
|
||||
new InputStreamReader(
|
||||
Objects.requireNonNull(Main.class.getClassLoader()
|
||||
.getResourceAsStream("tietokanta.sql"))))) {
|
||||
sql = br.readAllAsString();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
//Lisää kuljetuspäivät asiakassarakkeeseen (v2.0.2->3.x.x)
|
||||
String[] sarakkeet = {"lauantaiKpl", "sunnuntaiKpl"};
|
||||
for (String sarake : sarakkeet) {
|
||||
for (String query : sql.split(";")) {
|
||||
try (Connection conn = haeYhteys()) {
|
||||
PreparedStatement stmt = conn.prepareStatement("alter table asiakkaat add column " + sarake + " int not null default 0");
|
||||
stmt.execute();
|
||||
conn.createStatement().execute(query);
|
||||
} catch (SQLException e) {
|
||||
if (!e.getMessage().contains("duplicate column name")) {
|
||||
handleException(e);
|
||||
|
||||
@@ -40,4 +40,11 @@ create table if not exists kuljetukset (
|
||||
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);
|
||||
Reference in New Issue
Block a user