Search in sources :

Example 1 with Result

use of com.gamebuster19901.excite.bot.database.Result in project ExciteBot by TheGameCommunity.

the class Wii method getRegistrationCode.

public String getRegistrationCode() {
    try {
        Result result = Table.selectColumnsFromWhere(ConsoleContext.INSTANCE, REGISTRATION_CODE, WIIS, new Comparison(WII_ID, EQUALS, wiiCode));
        if (result.next()) {
            String ret = result.getString(REGISTRATION_CODE);
            if (ret == null) {
                generateRegistrationCode();
                result = Table.selectColumnsFromWhere(ConsoleContext.INSTANCE, REGISTRATION_CODE, WIIS, new Comparison(WII_ID, EQUALS, wiiCode));
                if (result.next()) {
                    return result.getString(REGISTRATION_CODE);
                }
            } else {
                return ret;
            }
        } else {
            generateRegistrationCode();
            result = Table.selectColumnsFromWhere(ConsoleContext.INSTANCE, REGISTRATION_CODE, WIIS, new Comparison(WII_ID, EQUALS, wiiCode));
            if (result.next()) {
                return result.getString(REGISTRATION_CODE);
            }
        }
        throw new AssertionError();
    } catch (SQLException e) {
        throw new IOError(e);
    }
}
Also used : Comparison(com.gamebuster19901.excite.bot.database.Comparison) SQLException(java.sql.SQLException) IOError(java.io.IOError) Result(com.gamebuster19901.excite.bot.database.Result)

Example 2 with Result

use of com.gamebuster19901.excite.bot.database.Result in project ExciteBot by TheGameCommunity.

the class DiscordUser method getDiscordUsersWithUsername.

@Deprecated
@SuppressWarnings("rawtypes")
public static final DiscordUser[] getDiscordUsersWithUsername(MessageContext context, String username) {
    try {
        ArrayList<DiscordUser> users = new ArrayList<DiscordUser>();
        Result results = Table.selectAllFromWhere(context, DISCORD_USERS, new Comparison(DISCORD_NAME, LIKE, Table.makeSafe(username) + "_____"));
        while (results.next()) {
            users.add(new DiscordUser(results));
        }
        return users.toArray(new DiscordUser[] {});
    } catch (SQLException e) {
        throw new IOError(e);
    }
}
Also used : Comparison(com.gamebuster19901.excite.bot.database.Comparison) SQLException(java.sql.SQLException) IOError(java.io.IOError) ArrayList(java.util.ArrayList) Result(com.gamebuster19901.excite.bot.database.Result)

Example 3 with Result

use of com.gamebuster19901.excite.bot.database.Result in project ExciteBot by TheGameCommunity.

the class DiscordUser method getAllAdmins.

public static DiscordUser[] getAllAdmins() {
    try {
        PreparedStatement st = ConsoleContext.INSTANCE.getConnection().prepareStatement("SELECT * FROM discord_users INNER JOIN admins ON(discord_users.discordID = admins.discordID);");
        Result results = st.query();
        int columns = results.getColumnCount();
        DiscordUser[] operators = new DiscordUser[columns];
        for (int i = 0; i < columns; i++) {
            results.next();
            operators[i] = new DiscordUser(results);
        }
        return operators;
    } catch (SQLException e) {
        throw new AssertionError(e);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(com.gamebuster19901.excite.bot.database.sql.PreparedStatement) Result(com.gamebuster19901.excite.bot.database.Result)

Example 4 with Result

use of com.gamebuster19901.excite.bot.database.Result in project ExciteBot by TheGameCommunity.

the class DiscordServer method getKnownDiscordServers.

public static DiscordServer[] getKnownDiscordServers() {
    try {
        ArrayList<DiscordServer> servers = new ArrayList<DiscordServer>();
        Result results = Table.selectAllFrom(ConsoleContext.INSTANCE, DISCORD_SERVERS);
        while (results.next()) {
            servers.add(new DiscordServer(results));
        }
        return servers.toArray(new DiscordServer[] {});
    } catch (SQLException e) {
        throw new IOError(e);
    }
}
Also used : SQLException(java.sql.SQLException) IOError(java.io.IOError) ArrayList(java.util.ArrayList) Result(com.gamebuster19901.excite.bot.database.Result)

Example 5 with Result

use of com.gamebuster19901.excite.bot.database.Result in project ExciteBot by TheGameCommunity.

the class DiscordUser method getRegisteredWiis.

@Nullable
public Wii[] getRegisteredWiis() {
    try {
        HashSet<Wii> wiis = new HashSet<Wii>();
        Result result = Table.selectColumnsFromWhere(ConsoleContext.INSTANCE, WII_ID, WIIS, new Comparison(DISCORD_ID, EQUALS, getID()));
        while (result.next()) {
            wiis.add(Wii.getWii(result.getString(WII_ID)));
        }
        return (Wii[]) wiis.toArray(new Wii[] {});
    } catch (SQLException e) {
        throw new IOError(e);
    }
}
Also used : Comparison(com.gamebuster19901.excite.bot.database.Comparison) SQLException(java.sql.SQLException) IOError(java.io.IOError) HashSet(java.util.HashSet) Result(com.gamebuster19901.excite.bot.database.Result) Nullable(javax.annotation.Nullable)

Aggregations

Result (com.gamebuster19901.excite.bot.database.Result)12 SQLException (java.sql.SQLException)9 Comparison (com.gamebuster19901.excite.bot.database.Comparison)8 IOError (java.io.IOError)6 ArrayList (java.util.ArrayList)4 Player (com.gamebuster19901.excite.Player)2 MessageContext (com.gamebuster19901.excite.bot.command.MessageContext)2 PreparedStatement (com.gamebuster19901.excite.bot.database.sql.PreparedStatement)2 HashSet (java.util.HashSet)2 Nullable (javax.annotation.Nullable)2 Row (com.gamebuster19901.excite.bot.database.Row)1 Wii (com.gamebuster19901.excite.bot.user.Wii)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MessagingException (javax.mail.MessagingException)1