-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVersion.java
More file actions
executable file
·54 lines (49 loc) · 1.44 KB
/
Version.java
File metadata and controls
executable file
·54 lines (49 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package database;
/************************************************
* Not used yet, but when we start having releases, we will need to
* to update old databases
*/
import java.sql.ResultSet;
import database.DBConn;
import util.ErrorReport;
import util.Globals;
public class Version {
public Version (DBConn mDB) {
checkVersion(mDB);
if (!version.equals(Globals.VERSION)) {
System.out.println("DB version " + version + " new schema is " + Globals.VERSION);
updateDB();
}
}
public String getVersion () {return version;}
// all new columns and tables are checked here and added if not exists
// new columns and tables are also put into Schema.java
private void updateDB() {
System.out.println("No DB update");
}
private void checkVersion(DBConn mDB) {
try {
ResultSet rs = mDB.executeQuery("SELECT version from metaData");
if (rs.next()) version = rs.getString(1);
rs.close();
}
catch (Exception e){
ErrorReport.die(e, "Cannot get version");
}
}
private boolean hasTable(DBConn mDB, String name) throws Exception
{
ResultSet rs = mDB.executeQuery("show tables like '" + name + "'");
boolean retVal = rs.first();
rs.close();
return retVal;
}
private boolean hasColumn(DBConn mDB, String table, String column) throws Exception
{
ResultSet rs = mDB.executeQuery("show columns from " + table + " where field='" + column + "'");
boolean ret = rs.first();
rs.close();
return ret;
}
String version=null;
}