Exemplo n.º 1
0
Arquivo: main.c Projeto: Tayum/di0d
int main(void) {
	//PRIMARY SIZE OF THE DATABASE
	const int size = 4;
	investorList_t * investorList = investorList_new(size);
	database_t * database = database_new("investors.db");
	//SIZE OF PRIMARY DATABASE
	int countSize = database_getSize(database);
	printf("TOTAL INVESTORS: %i\n\n", countSize);
	//FILTERS FOR THE NEXT STEP
	int moneyFilter = 4000000;
	int projFilter = 10;
	//AMOUNT OF INVESTORS FITTING FILTERS
	int countFilter = database_readInvListWHERE(database, moneyFilter, projFilter, investorList);
	printf("=====CONDITIONAL READ=====\nInvestors with money invested < %i OR projects invested < %i: %i\n\n", moneyFilter, projFilter, countFilter);
	investorList_print(investorList);

	puts("=====READ INVESTOR (BY INDEX 3)=====");
	investor_t * investor = database_readInv(database, 3);
	if (investor != NULL) { //CHECKING IF SUCH AN INDEX EXISTS
		investor_print(investor);
	}

	puts("=====CREATE NEW INVESTOR=====");
	investor_fillSmp(investor, "Sample", "Samploff", 5.7, 10000, 4, 2000, 3, 11);
	database_createInv(database, investor);
	database_readInvList(database, investorList);
	investorList_print(investorList);

	puts("=====UPDATE INVESTOR (BY INDEX 2)=====");
	database_updateInv(database, investor, 2);
	database_readInvList(database, investorList);
	investorList_print(investorList);
	
	puts("=====DELETE INVESTOR (BY INDEX 3)=====");
	database_deleteInv(database, 3);
	database_readInvList(database, investorList);
	investorList_print(investorList);

	//end of program
	investor_free(investor);
	investorList_free(investorList);
	database_free(database);
	getch();
	return 0;
}
Exemplo n.º 2
0
int
database_load(struct database *db, const char *path, int prot_thresh_level,
              enum uproc_ecurve_format format)
{
    db->fwd = db->rev = NULL;
    db->idmap = NULL;
    db->prot_thresh = NULL;

    switch (prot_thresh_level) {
        case 2:
        case 3:
            db->prot_thresh = uproc_matrix_load(
                UPROC_IO_GZIP, "%s/prot_thresh_e%d", path, prot_thresh_level);
            if (!db->prot_thresh) {
                goto error;
            }
            break;

        case 0:
            break;

        default:
            uproc_error_msg(
                UPROC_EINVAL, "protein threshold level must be 0, 2, or 3");
            goto error;
    }

    db->idmap = uproc_idmap_load(UPROC_IO_GZIP, "%s/idmap", path);
    if (!db->idmap) {
        goto error;
    }
    db->fwd = uproc_ecurve_load(format, UPROC_IO_GZIP, "%s/fwd.ecurve", path);
    if (!db->fwd) {
        goto error;
    }
    db->rev = uproc_ecurve_load(format, UPROC_IO_GZIP, "%s/rev.ecurve", path);
    if (!db->rev) {
        goto error;
    }

    return 0;
error:
    database_free(db);
    return -1;
}
Exemplo n.º 3
0
int main(void) {
	EXCEPTION *e = exception_new();

	printf ( "NEW\n" );
	DATABASE *db = database_new();
	database_setException(db, e);
	exception_throw(e);

	printf ( "PARAM\n" );
	database_setHost(db, "localhost");
	database_setName(db, "template1");
	database_setUser(db, "postgres");
	database_setPassword(db, "postgres");

	printf ( "OPEN\n" );
	database_open(db);
	exception_throw(e);

	printf ( "VERSION" );
	char *ver = database_getVersion(db);
	exception_throw(e);
	printf ( " (%s)\n", ver );
	free(ver);

	printf ( "RANDOM" );
	int rnd = database_getRandom(db);
	exception_throw(e);
	printf ( " (%d)\n", rnd );

	printf ( "CLOSE\n" );
	database_close(db);
	exception_throw(e);

	printf ( "FREE\n" );
	database_free(db);
	exception_throw(e);

	exception_free(e);

	return 0;
}
Exemplo n.º 4
0
int main(void) {
	EXCEPTION *e = exception_new();

	printf ( "NEW\n" );
	DATABASE *db = database_new();
	database_setException(db, e);
	exception_throw(e);

	printf ( "PARAM\n" );
	database_setName(db, "sqlite.db");

	printf ( "OPEN\n" );
	database_open(db);
	exception_throw(e);

	printf ( "VERSION" );
	char *ver = database_getVersion(db);
	exception_throw(e);
	printf ( " (%s)\n", ver );
	free(ver);

	printf ( "RANDOM" );
	int rnd = database_getRandom(db);
	exception_throw(e);
	printf ( " (%d)\n", rnd );

	printf ( "CLOSE\n" );
	database_close(db);
	exception_throw(e);

	printf ( "FREE\n" );
	database_free(db);
	exception_throw(e);

	exception_free(e);

	return 0;
}