Skip to content

Commit

Permalink
[*] Changed the createBill method to create the value with type decim…
Browse files Browse the repository at this point in the history
…al(16, 2), does some language level updates
  • Loading branch information
Lei-Tin authored and ScottCTD committed Nov 6, 2022
1 parent b0ffe75 commit 90576de
Showing 1 changed file with 43 additions and 42 deletions.
85 changes: 43 additions & 42 deletions src/main/java/billgates/database/MySQLDatabaseGateway.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class MySQLDatabaseGateway implements DatabaseGateway {
private Connection con = null;
Expand Down Expand Up @@ -198,19 +196,20 @@ public void createBill(int billId) {
try{
Statement statement = con.createStatement();

String query = "create table bill" + billId + "\n" +
"(\n" +
" entry_id int auto_increment\n" +
" primary key,\n" +
" value decimal(16, 2) not null,\n" +
" date timestamp not null,\n" +
" currency varchar(5) null,\n" +
" description text null,\n" +
" `from` text null,\n" +
" `to` text null,\n" +
" location text null\n" +
");\n" +
"\n";
String query = String.format("""
CREATE TABLE bill%d
(
entry_id INT AUTO_INCREMENT
PRIMARY KEY,
value DECIMAL(16, 2) NOT NULL,
date TIMESTAMP NOT NULL,
currency VARCHAR(5) NULL,
description TEXT NULL,
`from` TEXT NULL,
`to` TEXT NULL,
location TEXT NULL
)
""", billId);

statement.execute(query);

Expand Down Expand Up @@ -242,35 +241,37 @@ public static void main(String[] args) {
// 0,
// ZoneId.of("US/Eastern"));
//
QueryBillData b = a.getBillData(1);
// QueryBillData b = a.getBillData(1);

for (QueryEntryData i : b.getEntries()) {
System.out.println(i.getValue());
System.out.println(i.getDate().toInstant().toEpochMilli());
a.createBill(2);

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
System.out.println(i.getDate().format(formatter));
}

ZonedDateTime insertedTime = ZonedDateTime.of(2022,
10,
25,
5,
24,
36,
1234,
ZoneId.of("US/Eastern"));

QueryEntryData entry = new QueryEntryData(3,
insertedTime,
94.0,
"CAD",
"NULL",
"NULL",
"NULL",
"NULL");

a.insertEntry(1, entry);
// for (QueryEntryData i : b.getEntries()) {
// System.out.println(i.getValue());
// System.out.println(i.getDate().toInstant().toEpochMilli());
//
// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
// System.out.println(i.getDate().format(formatter));
// }
//
// ZonedDateTime insertedTime = ZonedDateTime.of(2022,
// 10,
// 25,
// 5,
// 24,
// 36,
// 1234,
// ZoneId.of("US/Eastern"));
//
// QueryEntryData entry = new QueryEntryData(3,
// insertedTime,
// 94.0,
// "CAD",
// "NULL",
// "NULL",
// "NULL",
// "NULL");
//
// a.insertEntry(1, entry);
}

}

0 comments on commit 90576de

Please sign in to comment.