The UDK Data Layer*
*Some Assembly Required

Building a World?
Where Will It Sleep?

Worlds in the Unreal Development Kit (UDK) are realized with state-of-the-art graphics and tools. However, the UDK fails to provide persistent storage for persistent worlds.

Enter SQL2UDK.

SQL2UDK is an open source tool that simplifies integration of SQL databases with UDK applications. If you're building a first-person shooter with an achievement system, a Massively Multiplayer Online Game, or a data-driven simulation, this tool will save you time and frustration. It will help you stay focused on your world, no matter how big it grows.


How Does It Work?

The SQL2UDK tool inspects your database and automatically generates data access code in layers to interact with it. Using the generated code, you follow simple steps to make your own Windows library and integrate it in your UDK application.

Here's a complete example showing the original SQL code and the layers of code that were automatically generated from it:
Suppose you're working on a database to hold the world for an MMORPG. Your team's SQL programmer has created a stored procedure to handle creating player accounts. It looks like this:

CREATE PROCEDURE create_player (IN p_in_login varchar(50), in p_in_password varchar(50), out p_out_id integer)
     insert into players (Login, Password) values (p_in_login,p_in_password);
     select LAST_INSERT_ID() into p_out_id;

Knowing it will save you time and frustration, you run SQL2UDK and point it at your database. It inspects all the stored procedures and starts generating code to help you.

First, SQL2UDK generates code in C++ that calls out to the database, in this case MySQL. The function uses standard data types and can be used by any program written in C++. For instance, this code could also be used by your MMORPG's standalone login server to create players before they even touch an Unreal server.

void DbProcedures::createPlayer(const std::string& pInLogin, const std::string& pInPassword, int* pOutId)
     sql::Connection* connection = SraData::DbConnectionFactory::GetSingleton().getConnection();
     std::auto_ptr pstmt;
     pstmt.reset(connection->prepareStatement("CALL create_player(?,?,@param2)"));


          std::auto_ptr< sql::ResultSet > res;
          std::auto_ptr< sql::Statement > stmt;
          res.reset(stmt->executeQuery("SELECT @param2 from dual"));
          *pOutId = res->getInt(1);


UDK-Ready C++
Functions called via the UDK's DllBind feature must be declared in a particular way and use only a limited set of data types. To compensate, SQL2UDK must generate one more layer of C++ code to convert standard types to DllBind-compliant types.

__declspec(dllexport) void createPlayer(wchar_t* pInLogin, wchar_t* pInPassword, int* pOutId)

Finally, SQL2UDK creates the supporting code for an UnrealScript class that imports and declares the funtionality, making it available to the rest of your UDK application.

class SraDataManager extends Object DLLBind(SraData);

dllimport final function createPlayer(string pInLogin, string pInPassword, out int pOutId);