Esempio n. 1
0
    public void CreatingAndRemovingTableInDB()
    {
        DBInstance dbInstance = new DBInstance("sensor_readings");

        dbInstance.InitialiseSQLiteConnection();

        string newTableName = "test";

        dbInstance.ExecuteNonQuery(
            SensorReadingTableDetails.CreateTableSQLString(newTableName));

        bool doesTableExistAfterCreation = dbInstance.DoesTableExistInDB(newTableName);

        Debug.Log("Table '" + newTableName + "' should now exist: " + doesTableExistAfterCreation);

        dbInstance.ExecuteNonQuery(
            SensorReadingTableDetails.DropTableSQLString(newTableName));

        bool doesTableExistAfterRemoved = dbInstance.DoesTableExistInDB(newTableName);

        Debug.Log("Table '" + newTableName + "' should now not exist: " + doesTableExistAfterRemoved);

        dbInstance.CloseSQLiteConnection();

        if ((doesTableExistAfterCreation) && (!doesTableExistAfterRemoved))
        {
            Assert.Pass();
        }
        else
        {
            Assert.Fail();
        }
    }
    public void GetSensorReadingsFromTableInDB()
    {
        DBInstance dbInstance = new DBInstance(databaseName);

        dbInstance.InitialiseSQLiteConnection();
        SensorReadings = dbInstance.GetSensorReadingsFromTable(tableNameInDatabase);
        dbInstance.CloseSQLiteConnection();
    }
Esempio n. 3
0
    public void InsertingSensorReading()
    {
        DBInstance dbInstance = new DBInstance("sensor_readings");

        dbInstance.InitialiseSQLiteConnection();

        string newTableName = "testTable";

        dbInstance.ExecuteNonQuery(SensorReadingTableDetails.CreateTableSQLString(newTableName));

        int numberOfRowsBeforeAddition = dbInstance.GetNumberOfRowsInTable(newTableName);

        Debug.Log("Number of rows in table before addition: " + numberOfRowsBeforeAddition);

        BaseSensorReading newSensorReading = new BaseSensorReading
        {
            sensorName = " ",
            sensorType = Sensor.Type.Interaction,
            areaName   = " "
        };

        newSensorReading.SetDateTime(1, 1, 1, 1, 1, 1);

        string insertSensorReadingString = SensorReadingTableDetails.InsertSensorReadingSQLString(newSensorReading, "testBookmark", 0, newTableName);

        Debug.Log(insertSensorReadingString);
        dbInstance.ExecuteNonQuery(insertSensorReadingString);

        int numberOfRowsAfterAddition = dbInstance.GetNumberOfRowsInTable(newTableName);

        Debug.Log("Number of rows in table after addition: " + numberOfRowsAfterAddition);

        dbInstance.ExecuteNonQuery(SensorReadingTableDetails.DropTableSQLString(newTableName));
        dbInstance.CloseSQLiteConnection();

        if (numberOfRowsBeforeAddition == numberOfRowsAfterAddition - 1)
        {
            Assert.Pass();
        }
        else
        {
            Assert.Fail();
        }
    }
Esempio n. 4
0
    public void InitialiseAndCloseDBConnection()
    {
        DBInstance dbInstance = new DBInstance("sensor_readings");

        dbInstance.InitialiseSQLiteConnection();
        bool dbInitialised = dbInstance.IsDbConnectionEstablished();

        dbInstance.CloseSQLiteConnection();
        bool dbClosed = dbInstance.IsDbConnectionEstablished();

        if ((dbInitialised) && (!dbClosed))
        {
            Assert.Pass();
        }
        else
        {
            Assert.Fail();
        }
    }
Esempio n. 5
0
    private static DBInstance dbInstance;           // Database connection instance

    /*
     *  Consider defining an interface/parent class for these methods,
     *  as it is shared with the DBInterfaceForInputVectors class.
     */

    /// <summary>
    /// Utility method for initialising a connection to a specified database.
    /// </summary>
    /// <param name="databaseName">Name of database to be connected to.</param>
    public static void InitialiseDatabaseConnection(string databaseName)
    {
        dbInstance = new DBInstance(databaseName);
        dbInstance.InitialiseSQLiteConnection();
    }