Esempio n. 1
0
// Tests that the Variant::operator== method works for variant vector-variant
// vector comparison w/ typecasting
TEST_F(TestVariant, OperatorEQVariantVectorVariantVectorTypeCasting) {
    Variant v1(VariantVector() << (float) 124.8 << "1.0" << (double) 7);
    Variant v2(VariantVector() << (float) 124.8 << 1.0 << (double) 7);
    EXPECT_EQ(v1, v2);

    Variant v3(VariantVector() << (float) 124.8 << "1" << (double) 7);
    Variant v4(VariantVector() << (float) 124.8 << (float) 1.0 << (double) 7);
    EXPECT_EQ(v3, v4);
}
Esempio n. 2
0
// Tests that the Variant::operator!= method returns true for variant vector-
// variant map comparison (with data)
TEST_F(TestVariant, OperatorNEVariantVectorVariantMap) {
    {
        Variant v1 = VariantVector() << "123";
        VariantMap map;
        map["123"] = "456";
        Variant v2(map);
        EXPECT_NE(v1, v2);
    }
    {
        Variant v1 = VariantVector() << "123";
        VariantMap map;
        map["456"] = "123";
        Variant v2(map);
        EXPECT_NE(v1, v2);
    }
}
/**
 *
 * Retrieves databases and returns the results
 *
 * @return The results of the query
 */
QueryResult DatabaseConnection::selectDatabase(
        std::string database)
{

    // Execute query
    return execute(VariantVector() << "USE ?" << database);
}
/**
 *
 * Kills a query.
 *
 * @param uuid The uuid of the connection
 * @return void
 */
void DatabaseConnectionManager::killQuery(std::string uuid)
{
    DatabaseConnection *killingConnection;
    ConnectionRecord record;

    for (Connections::const_iterator it = connections.begin();
            it != connections.end(); ++it) {

        record = it->second;

        if (record.uuid == uuid) {

            // Reserve a database connection
            killingConnection = reserveDatabaseConnectionObj(DEFAULT_EXPIRY,
                                                             record.receiver);

            // Kill query
            call(killingConnection, Variant(), QueryEvent::KILL_QUERY,
                 VariantVector() << uuid);

            // Release connection, for sanity. Because there is alrady an
            // expiry, it will be auto-freed regardless.
            releaseDatabaseConnection(connections[killingConnection].uuid);

            // No need to look at any other connections
            break;
        }
    }
}
Esempio n. 5
0
// Tests that the Variant::operator== method works for string vector-variant
// vector comparison
TEST_F(TestVariant, OperatorEQStringVectorVariantVector) {
    std::vector<std::string> list;
    list.push_back("124.8");
    list.push_back("1");
    list.push_back("7");
    Variant v1(list);
    Variant v2(VariantVector() << (float) 124.8 << "1" << (double) 7);
    EXPECT_EQ(v1, v2);
}
/**
 *
 * Kills the query being executed by the given connection
 *
 * @param uuid the UUID of the connection to kill
 * @return the result of the kill query
 */
QueryResult DatabaseConnection::killQuery(std::string uuid)
{
    DatabaseConnection *connection;

    connection = dynamic_cast<DatabaseConnection *>(
                getDatabaseConnection(uuid));

    return execute(VariantVector() << "KILL QUERY "
                   + Variant(connection->connection_id).toString());
}
/**
 *
 * Connects to the database
 *
 * Note that this expects that the database driver has setup all the things in
 * the connection.
 *
 * @return A QueryResult. error.isError will be false on success.
 */
QueryResult DatabaseConnection::connect()
{
    QueryResult result;

    if (driver == nullptr) {

        // Get driver instance
        driver = get_driver_instance();

        // Init SQL thread
        driver->threadInit();
    }

    if (connection == nullptr) {

        try {

            connection = driver->connect(hostname, username,
                                                        password);
        } catch (SQLException &e) {

            result.error.isError = true;
            result.error.code = e.getErrorCode();
            result.error.string = e.getSQLState() + ": " + e.what();

            return result;
        }

        // Reset result
        result = QueryResult();

        // Get connection id
        result = this->execute(VariantVector() << "SELECT CONNECTION_ID()");
        if (result.rows.size() == 0 || result.error.isError) {

            // No row returned
            return result;
        }
        connection_id = result.rows.front().front().toUInt();

        // Reset result
        result = QueryResult();

        return result;
    }

    // Successful connection?
    return result;
}
Esempio n. 8
0
// Tests reading and writing of a single Variant vector variant from and to
// json files
TEST_F(TestVariant, FileIOJsonIOVariantVector) {
    TEST_JSON_SINGLE(VariantVector, VariantVector() << "test" << 123
                                    << nullptr);
}
Esempio n. 9
0
// Tests reading and writing of a single Variant vector variant from and to
// binary files
TEST_F(TestVariant, FileIOBinaryIOVariantVector) {
    TEST_BINARY_SINGLE(VariantVector, VariantVector() << "test" << 123
        << nullptr);
}
Esempio n. 10
0
// Tests that the Variant::operator!= method works for variant vector-variant
// vector comparison w/ typecasting
TEST_F(TestVariant, OperatorNEVariantVectorVariantVectorTypeCasting) {
    Variant v1(VariantVector() << (float) 7);
    Variant v2(VariantVector() << (double) 7.5);
    EXPECT_NE(v1, v2);
}
Esempio n. 11
0
// Tests that the Variant::operator== method returns true for variant vector-
// variant map comparison (no data)
TEST_F(TestVariant, OperatorEQVariantVectorVariantMap) {
    Variant v1 = VariantVector();
    Variant v2 = VariantMap();
    EXPECT_EQ(v1, v2);
}
Esempio n. 12
0
// Tests that the Variant::operator== method works for variant vector-variant
// vector comparison
TEST_F(TestVariant, OperatorEQVariantVectorVariantVector) {
    Variant v1(VariantVector() << (float) 124.8 << "1" << (double) 7);
    Variant v2(VariantVector() << (float) 124.8 << "1" << (double) 7);
    EXPECT_EQ(v1, v2);
}
Esempio n. 13
0
// Tests that the Variant::operator== method works for float-string vector
// comparison
TEST_F(TestVariant, OperatorEQFloatVariantVectorMultiElements) {
    Variant v1((float) 124.8);
    Variant v2(VariantVector() << (float) 124.8 << "1");
    EXPECT_EQ(v1, v2);
}
Esempio n. 14
0
// Tests that the Variant::operator== method works for float-string vector
// comparison
TEST_F(TestVariant, OperatorEQFloatVariantVector) {
    Variant v1((float) 124.8);
    Variant v2(VariantVector() << (float) 124.8);
    EXPECT_EQ(v1, v2);
}
/**
 *
 * Retrieves tables and returns the results
 *
 * @param std::string database The name of the database to get tables from
 * @return The results of the query
 */
QueryResult DatabaseConnection::getTables(std::string database)
{

    // Execute query
    return execute(VariantVector() << "SHOW TABLES FROM ?" << database);
}