Shadowrun: Awakened 29 September 2011 - Build 871
Public Member Functions | Protected Member Functions
RoutineAnalyzer::CppSetRoutine Class Reference

Creates C++ code that implements a procedure call to a MySQL SPROC http://dev.mysql.com/doc/refman/5.1/en/connector-net-tutorials-stored-routines-statements.html. More...

Inheritance diagram for RoutineAnalyzer::CppSetRoutine:

List of all members.

Public Member Functions

 CppSetRoutine (string sql)
override string GetCode ()
 Should implement creation of the defintion.
override string GetDeclaration ()
 Gets the declaration associated with this C++ function.

Protected Member Functions

override RoutineParamBase CreateRoutineParam (string sql, int index)
 Implements generating of objects for parameters, these will be children of RoutineParamBase.

Detailed Description

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

pstmt->execute();

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

SraData::DbConnectionFactory::GetSingleton().recycleConnection(connection); }

Definition at line 34 of file CppSetRoutine.cs.


Constructor & Destructor Documentation

RoutineAnalyzer::CppSetRoutine::CppSetRoutine ( string  sql) [inline]

Definition at line 36 of file CppSetRoutine.cs.

                                         : base(sql)
        {
        }

Member Function Documentation

override RoutineParamBase RoutineAnalyzer::CppSetRoutine::CreateRoutineParam ( string  sql,
int  index 
) [inline, protected, virtual]
Parameters:
sql
index
Returns:

Implements RoutineAnalyzer::RoutineBase.

Definition at line 115 of file CppSetRoutine.cs.

        {
            return new CppSetRoutineParam(sql, index);
        }
override string RoutineAnalyzer::CppSetRoutine::GetCode ( ) [inline, virtual]
Returns:

Implements RoutineAnalyzer::RoutineBase.

Definition at line 61 of file CppSetRoutine.cs.

References RoutineAnalyzer::RoutineBase::_name, RoutineAnalyzer::RoutineBase::_params, and GetDeclaration().

        {
            //start off with the declaration, then put in
            StringBuilder builder = new StringBuilder();
            builder.AppendLine(GetDeclaration().Replace("static __declspec(dllexport) ",""));
            builder.AppendLine("{");

            //create the prepared statement that we will call
            //this prepared statement include the routine name and a number of question marks
            //equal to the number of arguments
            builder.AppendLine("sql::Connection* connection = SraData::DbConnectionFactory::GetSingleton().getConnection();");
            //use auto_ptr so we don't lose any memory in here
            builder.AppendLine("std::auto_ptr<sql::PreparedStatement> pstmt;");
            builder.Append("pstmt.reset(connection->prepareStatement(\"CALL ");
            builder.Append(_name);
            builder.Append("(");
            for (int i = 0; i < _params.Count; ++i)
            {
                builder.Append(_params[i].GetParameter());
                if (_params[i] != _params.Last<RoutineParamBase>())
                    builder.Append(",");
            }
            builder.AppendLine(")\"));");

            //add the pre-execute code for each parameter
            for (int i = 0; i < _params.Count; ++i)
            {
                string code = _params[i].GetPreExecuteCode();
                if (string.IsNullOrEmpty(code))
                    continue;
                builder.AppendLine(code);
            }

            //add the execute statement
            builder.AppendLine();
            builder.AppendLine("pstmt->execute();");
            builder.AppendLine();

            //add the post-execute code for each parameter
            for (int i = 0; i < _params.Count; ++i)
            {
                string code = _params[i].GetPostExecuteCode();
                if (string.IsNullOrEmpty(code))
                    continue;
                builder.AppendLine(code);
            }

            builder.AppendLine("SraData::DbConnectionFactory::GetSingleton().recycleConnection(connection);");

            //close up the statement and return it
            builder.Append("}");
            return builder.ToString();
        }
override string RoutineAnalyzer::CppSetRoutine::GetDeclaration ( ) [inline, virtual]
Returns:

Implements RoutineAnalyzer::RoutineBase.

Definition at line 44 of file CppSetRoutine.cs.

References RoutineAnalyzer::RoutineBase::_name, RoutineAnalyzer::RoutineBase::_params, RoutineAnalyzer::ParseHelper::ConvertUnderscoreToCamelCase(), and RoutineAnalyzer::RoutineParamBase::GetDeclaration().

Referenced by GetCode().

        {
            StringBuilder builder = new StringBuilder();
            builder.Append("static __declspec(dllexport) void ");
            builder.Append(ParseHelper.ConvertUnderscoreToCamelCase(_name));
            builder.Append("(");
            foreach (RoutineParamBase param in _params)
            {
                builder.Append(param.GetDeclaration());
                if (param != _params.Last<RoutineParamBase>())
                    builder.Append(", ");
            }

            builder.Append(")");
            return builder.ToString();
        }

The documentation for this class was generated from the following file:

Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.

GNU Lesser General Public License 3 Sourceforge.net