//todo: CreatePlayerDataContext 구현
bool CreatePlayerDataContext::OnSQLExecute()
{
	DBHelper dbHelper;

	/*
	dbHelper.BindParamText( mPlayerName );

	dbHelper.BindResultColumnInt( &mPlayerId );

	if ( dbHelper.Execute( SQL_CreatePlayer ) )
	{
		if ( dbHelper.FetchRow() )
		{
			return true;
		}
	}
	*/

	dbHelper.BindParamText(mPlayerName);
	dbHelper.BindResultColumnInt( &mPlayerId );

	if (dbHelper.Execute(SQL_CreatePlayer))
	{
		if (dbHelper.FetchRow())
		{
			/// 적용받은 행이 하나도 없다면, 실패라고 간주하자
			return mPlayerId != -1;
		}
	}

	return false;
}
//todo: DeletePlayerDataContext 구현
bool DeletePlayerDataContext::OnSQLExecute()
{
	DBHelper dbHelper;
	/*
	dbHelper.BindParamInt( &mPlayerId );

	if ( dbHelper.Execute( SQL_DeletePlayer ) )
	{
		if ( dbHelper.FetchRow() )
		{
			return true;
		}
	}
	*/

	int result = 0;

	dbHelper.BindParamInt(&mPlayerId);
	dbHelper.BindResultColumnInt(&result);

	if (dbHelper.Execute(SQL_DeletePlayer))
	{
		if (dbHelper.FetchRow())
		{
			/// 적용받은 행이 하나도 없다면, 실패라고 간주하자
			return result != 0;
		}
	}


	return false;
}
bool LoadPlayerDataContext::OnSQLExecute()
{
	//ScopeElapsedCheck __scope_elapsed_check__( __FUNCSIG__ );
	TRACE_THIS;
	TRACE_PERF;

	DBHelper dbHelper;

	dbHelper.BindParamInt(&mPlayerId);

	dbHelper.BindResultColumnText(mPlayerName, MAX_NAME_LEN);
	dbHelper.BindResultColumnFloat(&mPosX);
	dbHelper.BindResultColumnFloat(&mPosY);
	dbHelper.BindResultColumnFloat(&mPosZ);
	dbHelper.BindResultColumnBool(&mIsValid);
	dbHelper.BindResultColumnText(mComment, MAX_COMMENT_LEN);

	if (dbHelper.Execute(SQL_LoadPlayer))
	{
		if (dbHelper.FetchRow())
		{
			return true;
		}
	}

	return false;
}
//todo: CreatePlayerDataContext 구현
bool CreatePlayerDataContext::OnSQLExecute()
{
	DBHelper dbHelper;
	dbHelper.BindParamText( mPlayerName );

	if ( dbHelper.Execute( SQL_CreatePlayer ) )
	{
		if (dbHelper.FetchRow())
		{
			return true;
		}
	}
	return false;
}
//todo: DeletePlayerDataContext 구현
bool DeletePlayerDataContext::OnSQLExecute()
{
	DBHelper dbHelper;

	dbHelper.BindParamInt( &mPlayerId );
	if ( dbHelper.Execute( SQL_DeletePlayer ) )
	{
		if ( dbHelper.FetchRow() )
		{
			return true;
		}
	}
	return false;
}
int main(int argc, char *argv[])
{
    try
    {
        DBHelper db;

        if (argc > 1)
        {
            db.connect(argv[1]);
        }
        else
        {
            db.connect("retstest");
        }

        db.tables();

        ResultColumnPtr col3(new CharResultColumn(256));
        db.bindColumn(3, col3);

        ResultColumnPtr col4(new CharResultColumn(256));
        db.bindColumn(4, col4);

        ResultColumnPtr col5(new CharResultColumn(256));
        db.bindColumn(5, col5);

        cout << "pre fetch" << endl;
        while (db.fetch())
        {
            cout << col3 << "    ";
            cout << col4 << "    ";
            cout << col5 << "    " << endl;
        }
    
        db.disconnect();
    }
    catch(std::exception& e)
    {
        cout << e.what() << endl;
    }
}
bool LoadPlayerDataContext::OnSQLExecute()
{
	DBHelper dbHelper;

	dbHelper.BindParamInt(&mPlayerId);

	dbHelper.BindResultColumnText(mPlayerName, MAX_NAME_LEN);
	dbHelper.BindResultColumnFloat(&mPosX);
	dbHelper.BindResultColumnFloat(&mPosY);
	dbHelper.BindResultColumnFloat(&mPosZ);
	dbHelper.BindResultColumnBool(&mIsValid);
	dbHelper.BindResultColumnText(mComment, MAX_COMMENT_LEN);

	if (dbHelper.Execute(SQL_LoadPlayer))
	{
		if (dbHelper.FetchRow())
		{
			return true;
		}
	}

	return false;
}
bool UpdatePlayerPositionContext::OnSQLExecute()
{
	DBHelper dbHelper;
	int result = 0;

	dbHelper.BindParamInt(&mPlayerId);
	dbHelper.BindParamFloat(&mPosX);
	dbHelper.BindParamFloat(&mPosY);
	dbHelper.BindParamFloat(&mPosZ);

	dbHelper.BindResultColumnInt(&result);

	if (dbHelper.Execute(SQL_UpdatePlayerPosition))
	{
		if (dbHelper.FetchRow())
		{
			return result != 0;
		}
	}

	return false;
}
bool UpdatePlayerCommentContext::OnSQLExecute()
{
	DBHelper dbHelper;
	int result = 0;
	dbHelper.BindParamInt(&mPlayerId);
	dbHelper.BindParamText(mComment);

	dbHelper.BindResultColumnInt(&result);

	if (dbHelper.Execute(SQL_UpdatePlayerComment))
	{
		if (dbHelper.FetchRow())
		{
			return result != 0;
		}
	}

	return false;
}
int main()
{
    DBHelper db;
    try
    {

        db.connect("retstest");

        string query("SELECT *");
        query.append("  FROM data:Property:ResidentialProperty");

        cout << db.executeQuery(query) << endl;

        SQLSMALLINT numcol = db.numResultCols();
        cout << "Search Result has " << numcol << " columns" << endl;

        for (int i = 1 ; i <= numcol; i++)
        {
            cout << db.describeColumn(i) << endl;
        }
    
        if (db.fetch())
        {
            cout << "There was data, how can this be?" << endl;
        }
        else
        {
            cout << "No data as expected" << endl;
        }

        db.disconnect();
    }
    catch (std::exception& e)
    {
        cout << e.what() << endl;
    }
}
int main(int argc, char *argv[])
{
    DBHelper db;

    if (argc != 3) {
        std::string program_name = boost::regex_replace(std::string(argv[0]), boost::regex(".*/"), "");
        std::cerr << "Usage: " << program_name << " dsn query" << std::endl;
        return 1;
    }
    std::string dsn(argv[1]);
    std::string query(argv[2]);

    try
    {
        db.connect(dsn);

        cout << db.executeQuery(query) << endl;

        int num = db.numResultCols();
        cout << "Search Result has " << num << " columns" << endl;
        num = db.rowCount();
        cout << "Search Result has " << num << " rows" << endl;

        cout << db.describeColumn(1) << endl;
        ResultColumnPtr col1(new CharResultColumn(1024));

        cout << db.describeColumn(2) << endl;
        ResultColumnPtr col2(new CharResultColumn(1024));

        db.setStmtAttr(SQL_ROWSET_SIZE, (SQLPOINTER) 2, -6);
    
        cout << "pre fetch" << endl;
        while (db.fetch())
        {
            db.getData(1, col1);
            db.getData(2, col2);
            cout << col1 << "    ";
            cout << col2 << endl;
        }

        db.disconnect();
    }
    catch (std::exception& e)
    {
        cout << e.what() << endl;
    }
}
Exemplo n.º 12
0
/// 테스트용 임시 
void DbTestFunc()
{
	{
		DBHelper dbHelper;

		dbHelper.BindParamText(L"DbTestPlayer");
		if (dbHelper.Execute(SQL_CreatePlayer))
		{
			if (dbHelper.FetchRow())
			{
				printf("ok");
			}
		}
	}
	{
		DBHelper dbHelper;

		int uid = 100;
		float x = 2301.34f;
		float y = 56000.78f;
		float z = 990002.32f;

		dbHelper.BindParamInt(&uid);
		dbHelper.BindParamFloat(&x);
		dbHelper.BindParamFloat(&y);
		dbHelper.BindParamFloat(&z);

		if (dbHelper.Execute(SQL_UpdatePlayerPosition))
		{
			if (dbHelper.FetchRow())
			{
				printf("ok");
			}
		}
	}

	{
		DBHelper dbHelper;

		int uid = 100;

		dbHelper.BindParamInt(&uid);
		dbHelper.BindParamText(L"Update된 코멘트..입니다.");
		if (dbHelper.Execute(SQL_UpdatePlayerComment))
		{
			if (dbHelper.FetchRow())
			{
				printf("ok");
			}
		}
	}

	{
		DBHelper dbHelper;

		int uid = 100;
		bool v = true;
		dbHelper.BindParamInt(&uid);
		dbHelper.BindParamBool(&v);
		if (dbHelper.Execute(SQL_UpdatePlayerValid))
		{
			if (dbHelper.FetchRow())
			{
				printf("ok");
			}
		}
	}

	{
		DBHelper dbHelper;

		int uid = 100;
		dbHelper.BindParamInt(&uid);

		wchar_t name[32];
		float x = 0;
		float y = 0;
		float z = 0;
		bool valid = false;
		wchar_t comment[256];

		dbHelper.BindResultColumnText(name, 32);
		dbHelper.BindResultColumnFloat(&x);
		dbHelper.BindResultColumnFloat(&y);
		dbHelper.BindResultColumnFloat(&z);
		dbHelper.BindResultColumnBool(&valid);
		dbHelper.BindResultColumnText(comment, 256);

		if (dbHelper.Execute(SQL_LoadPlayer))
		{
			if (dbHelper.FetchRow())
			{
				printf("\n%ls %f %f %f %d %ls\n", name, x, y, z, valid, comment);
			}
		}
	}

	{
		DBHelper dbHelper;

		int uid = 100;

		dbHelper.BindParamInt(&uid);
		if (dbHelper.Execute(SQL_DeletePlayer))
		{
			if (dbHelper.FetchRow())
			{
				printf("ok");
			}
		}
	}

}
int main()
{
    DBHelper db;

    try
    {
        db.connect("retstest");

        string query("SELECT ListingID,ListDate");
        query.append("  FROM data:Property:RES");
        query.append(" WHERE ListPrice > 0");

        cout << db.executeQuery(query) << endl;

        int num = db.numResultCols();
        cout << "Search Result has " << num << " columns" << endl;
        num = db.rowCount();
        cout << "Search Result has " << num << " rows" << endl;

        cout << db.describeColumn(1) << endl;

        ResultColumnPtr col1(new CharResultColumn(1024));
        db.bindColumn(1, col1);

        cout << db.describeColumn(2) << endl;

        ResultColumnPtr col2(new TimestampResultColumn());
        db.bindColumn(2, col2);
    
        cout << "pre fetch" << endl;
        while (db.fetch())
        {
            cout << col1 << "    ";
            cout << col2 << endl;
        }

        db.disconnect();
    }
    catch (std::exception& e)
    {
        cout << e.what() << endl;
    }
}