Shadowrun: Awakened 29 September 2011 - Build 871
Public Member Functions | Protected Attributes | Properties | Private Member Functions | Static Private Member Functions
RoutineAnalyzer::RoutineParamBase Class Reference

Implements the core functionality of a routine parameter Child classes of this class implement specific code generation and logic. More...

Inheritance diagram for RoutineAnalyzer::RoutineParamBase:

List of all members.

Public Member Functions

abstract string GetDeclaration ()
virtual string GetParameter ()
 Returns the parameter marked used while setting up the CALL statement to the database For an IN parameter, this is just a question mark For an OUT parameter, this must be a unique name we query for later.
abstract string GetPostExecuteCode ()
abstract string GetPreExecuteCode ()
 RoutineParamBase (string sql, int index)

Protected Attributes

int _index
bool _isInParam
string _name
string _sql
ParameterTypes _type

Properties

string Name [get]

Private Member Functions

void Parse (string sql)
 Analyzes the declaration and populates this object with the logical representation.

Static Private Member Functions

static ParameterTypes ConvertParameterType (string paramType, bool isIn)
 Given a string describing the parameter type and a flag indicating whether it was in or out, this determines the Parameter type.

Detailed Description

Definition at line 25 of file RoutineParamBase.cs.


Constructor & Destructor Documentation

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

Definition at line 76 of file RoutineParamBase.cs.

References _index, and Parse().

        {
            _index = index;

            Parse(sql);
        }

Member Function Documentation

static ParameterTypes RoutineAnalyzer::RoutineParamBase::ConvertParameterType ( string  paramType,
bool  isIn 
) [inline, static, private]
Parameters:
paramType
isIn
Returns:

Definition at line 36 of file RoutineParamBase.cs.

Referenced by Parse().

        {
            paramType = paramType.ToUpper();
            if (isIn)
            {
                if (paramType.Contains("VARCHAR"))
                    return ParameterTypes.StringByValue;
                else
                    return ParameterTypes.IntByValue;
            }
            else
            {
                if (paramType.Contains("VARCHAR"))
                    return ParameterTypes.StringByReference;
                else
                    return ParameterTypes.IntByReference;
            }
        }
abstract string RoutineAnalyzer::RoutineParamBase::GetDeclaration ( ) [pure virtual]
virtual string RoutineAnalyzer::RoutineParamBase::GetParameter ( ) [inline, virtual]
Parameters:
paramIndex
Returns:

Reimplemented in RoutineAnalyzer::CppWrapperSetRoutineParam.

Definition at line 128 of file RoutineParamBase.cs.

References _index, and _isInParam.

Referenced by RoutineAnalyzer::CppWrapperSetRoutine::GetCode(), and RoutineAnalyzer::CppSetRoutineParam::GetPostExecuteCode().

        {
            //if it is just an input param, then we use a quotation mark as the param maker
            if (_isInParam)
                return "?";

            //if it is an output parameter, then we create a variable name based on the index
            return string.Format("@param{0}", _index);
        }
abstract string RoutineAnalyzer::RoutineParamBase::GetPostExecuteCode ( ) [pure virtual]
abstract string RoutineAnalyzer::RoutineParamBase::GetPreExecuteCode ( ) [pure virtual]
void RoutineAnalyzer::RoutineParamBase::Parse ( string  sql) [inline, private]
Parameters:
declaration

Definition at line 87 of file RoutineParamBase.cs.

References _isInParam, _name, _sql, _type, and ConvertParameterType().

Referenced by RoutineParamBase().

        {
            //save the original SQL
            _sql = sql;

            //break up the parameters by their spaces
            //NOTE: This is a very brittle way of parsing and depends on consistent SQL coding style in the database
            string[] parts = sql.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            string direction;
            string name;
            string type;

            //We assuming the delcaration takes the form: DIRECTION NAME TYPE
            //if they didn't use an explicit IN declaration, then it is assumed to be one
            if (parts.Length == 2)
            {
                direction = "IN";
                name = parts[0];
                type = parts[1];
            }
            else
            {
                direction = parts[0].ToUpper();
                name = parts[1];
                type = parts[2];
            }

            //if the direction is IN, then it's an in paramter (otherwise it is an OUT)
            _isInParam = direction.ToUpper() == "IN";
            _type = ConvertParameterType(type, _isInParam);
            _name = name;
        }

Member Data Documentation

Definition at line 59 of file RoutineParamBase.cs.

Referenced by Parse().

Definition at line 60 of file RoutineParamBase.cs.

Referenced by Parse().


Property Documentation

string RoutineAnalyzer::RoutineParamBase::Name [get]

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