Shadowrun: Awakened 29 September 2011 - Build 871
Public Member Functions | Static Public Member Functions
RoutineAnalyzer::CppSetRoutineParam Class Reference
Inheritance diagram for RoutineAnalyzer::CppSetRoutineParam:

List of all members.

Public Member Functions

 CppSetRoutineParam (string sql, int index)
 Constructor.
override string GetDeclaration ()
 Returns the declaration for the parameter in C++.
override string GetPostExecuteCode ()
override string GetPreExecuteCode ()
 Returns the code for before the execute code.

Static Public Member Functions

static string GetCppGetOperation (ParameterTypes type)
 Gets the MySQL library function associated with the given parameter type NOTE: only the reference types need to be implemented because get operations are only performed when it is an OUT parameter (which maps to a ByReference type)
static string GetCppSetOperation (ParameterTypes type)
 Gets the MySQL library function associated with the given parameter type NOTE: Only byValue types need to be implemented because set operations are only performed when it is an IN parameter (which maps to a ByValue type)
static string GetCppWrapperType (ParameterTypes type)
 Returns the C++ type associated with the given parameter type.

Detailed Description

Definition at line 8 of file CppSetRoutineParam.cs.


Constructor & Destructor Documentation

RoutineAnalyzer::CppSetRoutineParam::CppSetRoutineParam ( string  sql,
int  index 
) [inline]
Parameters:
sql
index

Definition at line 72 of file CppSetRoutineParam.cs.

            : base(sql, index)
        {
        }

Member Function Documentation

static string RoutineAnalyzer::CppSetRoutineParam::GetCppGetOperation ( ParameterTypes  type) [inline, static]
Parameters:
type
Returns:

Definition at line 19 of file CppSetRoutineParam.cs.

Referenced by GetPostExecuteCode(), and RoutineAnalyzer::CppGetRoutineParam::GetPostExecuteCode().

        {
            switch (type)
            {
                case ParameterTypes.IntByReference: return "getInt";
                case ParameterTypes.StringByReference: return "getString";
                default: return "getInt";
            }
        }
static string RoutineAnalyzer::CppSetRoutineParam::GetCppSetOperation ( ParameterTypes  type) [inline, static]
Parameters:
type
Returns:

Definition at line 36 of file CppSetRoutineParam.cs.

Referenced by GetPreExecuteCode().

        {
            switch (type)
            {
                case ParameterTypes.IntByValue: return "setInt";
                case ParameterTypes.StringByValue: return "setString";
                default: return "setInt";
            }
        }
static string RoutineAnalyzer::CppSetRoutineParam::GetCppWrapperType ( ParameterTypes  type) [inline, static]
Parameters:
type
Returns:

Definition at line 51 of file CppSetRoutineParam.cs.

Referenced by GetDeclaration(), and RoutineAnalyzer::CppGetRoutineParam::GetDeclaration().

        {
            switch (type)
            {
                case ParameterTypes.IntByReference: return "int*";
                case ParameterTypes.IntByValue: return "int";
                case ParameterTypes.StringByReference: return "std::string&";
                case ParameterTypes.StringByValue: return "const std::string&";

                default:
                    throw new Exception("Error: Cpp type not implemented!");
            }
        }
override string RoutineAnalyzer::CppSetRoutineParam::GetDeclaration ( ) [inline, virtual]
Returns:

Implements RoutineAnalyzer::RoutineParamBase.

Definition at line 81 of file CppSetRoutineParam.cs.

References RoutineAnalyzer::RoutineParamBase::_type, RoutineAnalyzer::ParseHelper::ConvertUnderscoreToCamelCase(), GetCppWrapperType(), and RoutineAnalyzer::RoutineParamBase::Name.

        {
            string cppType = GetCppWrapperType(_type);
            string cppName = ParseHelper.ConvertUnderscoreToCamelCase(Name);
            return string.Format("{0} {1}", cppType, cppName);
        }
override string RoutineAnalyzer::CppSetRoutineParam::GetPostExecuteCode ( ) [inline, virtual]

Implements RoutineAnalyzer::RoutineParamBase.

Definition at line 122 of file CppSetRoutineParam.cs.

References RoutineAnalyzer::RoutineParamBase::_isInParam, RoutineAnalyzer::RoutineParamBase::_type, RoutineAnalyzer::ParseHelper::ConvertUnderscoreToCamelCase(), GetCppGetOperation(), RoutineAnalyzer::RoutineParamBase::GetParameter(), and RoutineAnalyzer::RoutineParamBase::Name.

        {
            //in parameters never have post execute code
            if (_isInParam)
                return "";

            //OUT parameters always have post execute code

            //the post execute code will query the database for the variable named
            //for this argument's ParamMarker.  It will traverse the result set
            //of this query, then 
            StringBuilder builder = new StringBuilder();

            //we create a new scope so we don't have name collisions amongst multiple out parameters
            builder.AppendLine("{");

            //use auto_ptr for all declarations in here so we don't lost anything
            builder.AppendLine("std::auto_ptr< sql::ResultSet > res;");
            //we create a whole new statement because the MySQL library doesn't like re-using the prepared statement used for the execute
            //In the future, it does seem like some performance gain could be had by eliminating making a whole new object (how much? who knows)
            builder.AppendLine("std::auto_ptr< sql::Statement > stmt;");
            builder.AppendLine("stmt.reset(connection->createStatement());");
            //we query out of the database the value of the variable we utilized during the execute (same name as our param marker)
            builder.AppendLine(string.Format("res.reset(stmt->executeQuery(\"SELECT {1} from dual\"));",
                                ParseHelper.PreparedStmtName, GetParameter()));
            builder.AppendLine("res->next();");
            string cppName = ParseHelper.ConvertUnderscoreToCamelCase(Name);
            string getOperation = GetCppGetOperation(_type);
            if (_type == ParameterTypes.IntByReference)
                builder.AppendLine(string.Format("*{0} = res->{1}(1);", cppName, getOperation));
            else if (_type == ParameterTypes.StringByReference)
                builder.AppendLine(string.Format("{0} = res->getString(1);"));
            else
                throw new Exception("Error, parameter type not implemented");

            //close the new scope
            builder.AppendLine("}");

            return builder.ToString();
        }
override string RoutineAnalyzer::CppSetRoutineParam::GetPreExecuteCode ( ) [inline, virtual]
Returns:

Implements RoutineAnalyzer::RoutineParamBase.

Definition at line 92 of file CppSetRoutineParam.cs.

References RoutineAnalyzer::RoutineParamBase::_index, RoutineAnalyzer::RoutineParamBase::_isInParam, RoutineAnalyzer::RoutineParamBase::_type, RoutineAnalyzer::ParseHelper::ConvertUnderscoreToCamelCase(), GetCppSetOperation(), and RoutineAnalyzer::RoutineParamBase::Name.

        {
            //if this isn't an in param, then we do not perform a pre-execute work
            //our pre-execute setup is just sending in our named variable
            if (!_isInParam)
                return "";

            //If this is an IN paramter, then we have to set the value in the prepared statement
            //before execute is called.

            if (_type == ParameterTypes.StringByValue)
            {
                return string.Format("{0}->setString({1},{2});",
                                         ParseHelper.PreparedStmtName,
                                         _index + 1,   //MySQL library starts counting at 1
                                         ParseHelper.ConvertUnderscoreToCamelCase(Name));
            }
            else
            {
                string setOperation = GetCppSetOperation(_type);
                return string.Format("{0}->{1}({2},{3});",
                                         ParseHelper.PreparedStmtName,
                                         setOperation,
                                         _index + 1,   //MySQL library starts counting at 1
                                         ParseHelper.ConvertUnderscoreToCamelCase(Name));
            }

            throw new Exception("Error determining argument CPP code");
        }

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