Skip to content

Commit

Permalink
Added extra tests and solved bug with columns using CustomSql component
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelAl committed Jul 24, 2020
1 parent 1a96264 commit da0a698
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 16 deletions.
6 changes: 4 additions & 2 deletions src/samuelal/squelized/QueryBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ public static String displayRecords(String tableName, String[] columns) {
SelectQuery selectQuery = new SelectQuery().addCustomFromTable(tableName);

for (String column : columns) {
selectQuery.addCustomColumns(column);
selectQuery.addCustomColumns(new CustomSql(column));
}

String query = selectQuery.validate().toString();

System.out.println(query);

return query;
}

Expand All @@ -78,7 +80,7 @@ public static String displayRecords(String tableName, String[] columns, String o
SelectQuery selectQuery = new SelectQuery().addCustomFromTable(tableName);

for (String column : columns) {
selectQuery.addCustomColumns(column);
selectQuery.addCustomColumns(new CustomSql(column));
}

selectQuery.addCustomOrdering(orderColumn, ascending ? Dir.ASCENDING : Dir.DESCENDING);
Expand Down
31 changes: 22 additions & 9 deletions src/samuelal/squelized/SQLConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ protected void welcome() {
* runs SQL query through connection
* and returns Table object with results
*
* @param String query
* @return Table results
* @param query
* @return results
*/
public Table runQuery(String query)
{
Expand Down Expand Up @@ -149,8 +149,8 @@ public Table runQuery(String query)
* gets all the data of a table and
* generates a Processing Table with it
*
* @param String tableName
* @return Table results
* @param tableName
* @return results
*/
public Table getTable(String tableName) {
return runQuery(QueryBuilder.displayAllTableRecords(tableName));
Expand All @@ -162,27 +162,40 @@ public Table getTable(String tableName) {
*
* @param tableName
* @param columnName
* @return Table results
* @return results
*/
public Table getColumn(String tableName, String columnName) {
return getColumns(tableName, new String[] {columnName});
}

/**
* gets all the date of a table's specified columns
* and generates Processing Table
*
* @param String tableName
* @param String[] columnNames
* @return Table results
* @param tableName
* @param columnNames
* @return results
*/
public Table getColumns(String tableName, String[] columnNames) {
return runQuery(QueryBuilder.displayRecords(tableName, columnNames));
}

/**
* Inserts values into specified columns
* (inserts only one row)
*
* @param tableName
* @param columnNames
* @param data
*/
public void insertIntoColumns(String tableName, String[] columnNames, Object[] data) {
runQuery(QueryBuilder.insertData(tableName, columnNames, data));
}

/**
* return the version of the Library.
*
* @return String
* @return VERSION
*/
public static String version() {
return VERSION;
Expand Down
19 changes: 14 additions & 5 deletions tests/samuelal/squelized/SQLConnectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,34 @@

import java.util.Properties;

import org.junit.Assert;
import org.junit.jupiter.api.Test;

class SQLConnectionTest {

@Test
void testGetSQLConnection() {
Properties mySqlProps = new Properties();

Properties mySqlProps;
Properties postGreSQLProps;
public SQLConnectionTest() {
mySqlProps = new Properties();
mySqlProps.setProperty("user", "root");
mySqlProps.setProperty("password", "1234");
mySqlProps.setProperty("useUnicode", "true");
mySqlProps.setProperty("useJDBCCompliantTimezoneShift", "true");
mySqlProps.setProperty("useLegacyDatetimecode", "true");
mySqlProps.setProperty("serverTimezone", "UTC");
}

@Test
void testGetSQLConnection() {
SQLConnection mysql = new MySQLConnection("jdbc:mysql://localhost:3306/squelized_test", mySqlProps);
}

@Test
void testGetDatabaseType() {
fail("Not yet implemented"); // TODO
SQLConnection mySQL = new MySQLConnection("jdbc:mysql://localhost:3306/squelized_test", mySqlProps);
Assert.assertEquals(DatabaseType.MYSQL, mySQL.getDatabaseType());
SQLConnection sqlLite = new SQLiteConnection("jdbc:sqlite:E:/Personal Projects/SQuelized/chinook/chinook.db");
Assert.assertEquals(DatabaseType.SQLITE, sqlLite.getDatabaseType());
}

@Test
Expand Down

0 comments on commit da0a698

Please sign in to comment.