Skip to content

Commit fe76bc1

Browse files
author
Даниил
committed
Implementation of getDbType, getDbVersion, test
1 parent b0ccc8f commit fe76bc1

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

src/main/java/ru/fusionsoft/dbgit/mssql/DBAdapterMssql.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,15 +1202,27 @@ public IFactoryDBConvertAdapter getConvertAdapterFactory() {
12021202

12031203
@Override
12041204
public String getDbType() {
1205-
// TODO Auto-generated method stub
1206-
return null;
1205+
return IFactoryDBConvertAdapter.MSSQL;
12071206
}
12081207

1209-
@Override
1210-
public String getDbVersion() {
1211-
// TODO Auto-generated method stub
1212-
return null;
1213-
}
1208+
@Override
1209+
public String getDbVersion() {
1210+
try {
1211+
Statement stmt = getConnection().createStatement();
1212+
1213+
//Gives 8.00, 9.00, 10.00 and 10.50 for SQL 2000, 2005, 2008 and 2008R2 respectively.
1214+
String query = "SELECT left(cast(serverproperty('productversion') as varchar), 4)";
1215+
1216+
ResultSet resultSet = stmt.executeQuery(query);
1217+
resultSet.next();
1218+
String result = resultSet.getString(1);
1219+
1220+
resultSet.close();
1221+
stmt.close();
1222+
return result;
1223+
1224+
} catch (SQLException e) { return "";}
1225+
}
12141226

12151227
@Override
12161228
public void createSchemaIfNeed(String schemaName) throws ExceptionDBGit {

src/test/java/ru/fusionsoft/dbgit/mssql/DBAdapterMssqlTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.junit.Test;
99

1010
import ru.fusionsoft.dbgit.adapters.AdapterFactory;
11+
import ru.fusionsoft.dbgit.adapters.IFactoryDBConvertAdapter;
1112
import ru.fusionsoft.dbgit.core.DBGitConfig;
1213
import ru.fusionsoft.dbgit.dbobjects.*;
1314
import ru.fusionsoft.dbgit.utils.ConsoleWriter;
@@ -585,6 +586,20 @@ public void userHasRightsToGetDdlOfOtherUsers() throws Exception{
585586

586587
}
587588

589+
@Test
590+
public void getDbType(){
591+
String type = testAdapter.getDbType();
592+
assertFalse(type.isEmpty());
593+
assertEquals(IFactoryDBConvertAdapter.MSSQL, type);
594+
}
595+
596+
@Test
597+
public void getDbVersion(){
598+
String version = testAdapter.getDbVersion();
599+
assertFalse(version.isEmpty());
600+
}
601+
602+
588603
public DBAdapterMssql createAdapterWithCredentials(String username, String password, String url) throws Exception{
589604
Properties props = new Properties();
590605
props.setProperty("url", Objects.nonNull(url) ? url : TEST_CONN_STRING);

0 commit comments

Comments
 (0)