GList *PyMySQLGetDatabaseList(const char *user, const char *password)
{
	PyObject *rs;

	if (PyMySQLConnect("", user, password) < 0)
		return NULL;

	rs = PyRun_String("PyUpdateCommandReturn(\"Show databases\")", Py_eval_input, pdict, pdict);
	if (rs)
	{
		unsigned int i;
		GList *glist = NULL;
		RowSet* list = ConvertPythonToRowset(rs);
		if (!list)
			return NULL;
		for (i = 0; i < list->rows; i++)
			glist = g_list_append(glist, g_strdup(list->data[i][0]));
		FreeRowset(list);
		return glist;
	}
	else
	{
		PyErr_Print();
		return NULL;
	}
}
示例#2
0
extern void
CommandRelationalSelect(char *sz)
{
    unsigned int i, j;
    RowSet *rs;

    if (!sz || !*sz) {
        outputl(_("You must specify a sql query to run."));
        return;
    }

    rs = RunQuery(sz);
    if (!rs)
        return;

    if (rs->rows == 0) {
        outputl(_("No rows found.\n"));
        return;
    }
#if USE_GTK
    if (fX)
        GtkShowQuery(rs);
    else
#endif
        for (i = 0; i < rs->rows; i++) {
            if (i == 1) {       /* Underline headings */
                char *line, *p;
                unsigned int k;
                int totalwidth = 0;
                for (k = 0; k < rs->cols; k++) {
                    totalwidth += rs->widths[k] + 1;
                    if (k != 0)
                        totalwidth += 2;
                }
                line = malloc(totalwidth + 1);
                memset(line, '-', totalwidth);
                p = line;
                for (k = 0; k < rs->cols - 1; k++) {
                    p += rs->widths[k];
                    p[1] = '|';
                    p += 3;
                }
                line[totalwidth] = '\0';
                outputl(line);
                free(line);
            }

            for (j = 0; j < rs->cols; j++) {
                if (j > 0)
                    output(" | ");

                outputf("%*s", (int) rs->widths[j], rs->data[i][j]);
            }
            outputl("");
        }
    FreeRowset(rs);
}
示例#3
0
int
RunQueryValue(const DBProvider * pdb, const char *query)
{
    RowSet *rs;
    rs = pdb->Select(query);
    if (rs && rs->rows > 1) {
        int id = (int)strtol(rs->data[1][0], NULL, 0);
        FreeRowset(rs);
        return id;
    } else
        return -1;
}
示例#4
0
const char *
TestDB(DBProviderType dbType)
{
    char *ret = NULL;
    DBProvider *pdb;
    RowSet *rs;
    if ((pdb = ConnectToDB(dbType)) == NULL)
        return _("Database connection test failed, installation problem!\n");

    /* Check main table is present */
    rs = pdb->Select("COUNT(*) from session");
    if (rs) {                   /* Success */
        FreeRowset(rs);
    } else
        ret = (_("Database table check failed!\n" "The session table is missing."));

    pdb->Disconnect();
    return ret;
}
示例#5
0
GList *
PyPostgreGetDatabaseList(const char *user, const char *password, const char *hostname)
{
    RowSet *rs;

    if (PyPostgreConnect("", user, password, hostname) < 0)
        return NULL;

    rs = PySelect("datname from pg_database");
    if (rs) {
        unsigned int i;
        GList *glist = NULL;
        for (i = 1; i < rs->rows; i++)
            glist = g_list_append(glist, g_strdup(rs->data[i][0]));
        FreeRowset(rs);
        return glist;
    } else {
        PyErr_Print();
        return NULL;
    }
}
extern statcontext *relational_player_stats_get(const char *player0, const char *player1)
{
	int id0 = -1;
	int id1 = -1;
	DBProvider *pdb = NULL;
	char *query[2];
	int i;
	char *buf;
	RowSet *rs;
	statcontext *psc;

	g_return_val_if_fail(player0, NULL);

	if ((pdb = ConnectToDB(dbProviderType)) == NULL)
		return NULL;

	id0 = GetPlayerId(pdb, player0);
	if (player1)
		id1 = GetPlayerId(pdb, player1);
	if (id0 == -1 || (player1 && id1 == -1))
		return NULL;

	psc = g_new0(statcontext, 1);

	if (!player1) {
		query[0] =
		    g_strdup_printf("where matchstat.player_id = %d", id0);
		query[1] =
		    g_strdup_printf("NATURAL JOIN session WHERE "
				    "(session.player_id0 = %d OR session.player_id1 = %d) "
				    "AND matchstat.player_id != %d", id0, id0,
				    id0);
	} else {
		query[0] = g_strdup_printf("NATURAL JOIN session WHERE "
					   "((session.player_id0 = %d OR session.player_id1 = %d) "
					   " AND "
					   " (session.player_id0 = %d OR session.player_id1 = %d))"
					   "AND matchstat.player_id = %d", id0,
					   id0, id1, id1, id0);
		query[1] =
		    g_strdup_printf("NATURAL JOIN session WHERE "
				    "((session.player_id0 = %d OR session.player_id1 = %d) "
				    " AND "
				    " (session.player_id0 = %d OR session.player_id1 = %d))"
				    "AND matchstat.player_id = %d", id0, id0,
				    id1, id1, id1);
	}

	IniStatcontext(psc);
	for (i = 0; i < 2; ++i) {
		buf = g_strdup_printf("SUM(total_moves),"
				      "SUM(unforced_moves),"
				      "SUM(total_cube_decisions),"
				      "SUM(close_cube_decisions),"
				      "SUM(doubles),"
				      "SUM(takes),"
				      "SUM(passes),"
				      "SUM(very_bad_moves),"
				      "SUM(bad_moves),"
				      "SUM(doubtful_moves),"
				      "SUM(unmarked_moves),"
				      "SUM(very_unlucky_rolls),"
				      "SUM(unlucky_rolls),"
				      "SUM(unmarked_rolls),"
				      "SUM(lucky_rolls),"
				      "SUM(very_lucky_rolls),"
				      "SUM(missed_doubles_below_cp),"
				      "SUM(missed_doubles_above_cp),"
				      "SUM(wrong_doubles_below_dp),"
				      "SUM(wrong_doubles_above_tg),"
				      "SUM(wrong_takes),"
				      "SUM(wrong_passes),"
				      "SUM(chequer_error_total_normalised),"
				      "SUM(error_missed_doubles_below_cp_normalised),"
				      "SUM(error_missed_doubles_above_cp_normalised),"
				      "SUM(error_wrong_doubles_below_dp_normalised),"
				      "SUM(error_wrong_doubles_above_tg_normalised),"
				      "SUM(error_wrong_takes_normalised),"
				      "SUM(error_wrong_passes_normalised),"
				      "SUM(luck_total_normalised)"
				      "from matchstat " "%s", query[i]);
		rs = pdb->Select(buf);
		g_free(buf);
		if ((!rs) || !strtol(rs->data[1][0], NULL, 0))
			return NULL;
		psc->anTotalMoves[i] = strtol(rs->data[1][0], NULL, 0);
		psc->anUnforcedMoves[i] = strtol(rs->data[1][1], NULL, 0);
		psc->anTotalCube[i] = strtol(rs->data[1][2], NULL, 0);
		psc->anCloseCube[i] = strtol(rs->data[1][3], NULL, 0);
		psc->anDouble[i] = strtol(rs->data[1][4], NULL, 0);
		psc->anTake[i] = strtol(rs->data[1][5], NULL, 0);
		psc->anPass[i] = strtol(rs->data[1][6], NULL, 0);
		psc->anMoves[i][SKILL_VERYBAD] =
		    strtol(rs->data[1][7], NULL, 0);
		psc->anMoves[i][SKILL_BAD] = strtol(rs->data[1][8], NULL, 0);
		psc->anMoves[i][SKILL_DOUBTFUL] =
		    strtol(rs->data[1][9], NULL, 0);
		psc->anMoves[i][SKILL_NONE] = strtol(rs->data[1][10], NULL, 0);
		psc->anLuck[i][LUCK_VERYBAD] = strtol(rs->data[1][11], NULL, 0);
		psc->anLuck[i][LUCK_BAD] = strtol(rs->data[1][12], NULL, 0);
		psc->anLuck[i][LUCK_NONE] = strtol(rs->data[1][13], NULL, 0);
		psc->anLuck[i][LUCK_GOOD] = strtol(rs->data[1][14], NULL, 0);
		psc->anLuck[i][LUCK_VERYGOOD] =
		    strtol(rs->data[1][15], NULL, 0);
		psc->anCubeMissedDoubleDP[i] = strtol(rs->data[1][16], NULL, 0);
		psc->anCubeMissedDoubleTG[i] = strtol(rs->data[1][17], NULL, 0);
		psc->anCubeWrongDoubleDP[i] = strtol(rs->data[1][18], NULL, 0);
		psc->anCubeWrongDoubleTG[i] = strtol(rs->data[1][19], NULL, 0);
		psc->anCubeWrongTake[i] = strtol(rs->data[1][20], NULL, 0);
		psc->anCubeWrongPass[i] = strtol(rs->data[1][21], NULL, 0);
		psc->arErrorCheckerplay[i][0] =
		    (float)g_ascii_strtod(rs->data[1][22], NULL);
		psc->arErrorMissedDoubleDP[i][0] =
		    (float)g_ascii_strtod(rs->data[1][23], NULL);
		psc->arErrorMissedDoubleTG[i][0] =
		    (float)g_ascii_strtod(rs->data[1][24], NULL);
		psc->arErrorWrongDoubleDP[i][0] =
		    (float)g_ascii_strtod(rs->data[1][25], NULL);
		psc->arErrorWrongDoubleTG[i][0] =
		    (float)g_ascii_strtod(rs->data[1][26], NULL);
		psc->arErrorWrongTake[i][0] =
		    (float)g_ascii_strtod(rs->data[1][27], NULL);
		psc->arErrorWrongPass[i][0] =
		    (float)g_ascii_strtod(rs->data[1][28], NULL);
		psc->arLuck[i][0] =
		    (float)g_ascii_strtod(rs->data[1][29], NULL);
		FreeRowset(rs);
	}
	psc->fMoves = 1;
	psc->fCube = 1;
	psc->fDice = 1;

	return psc;
}