![]() |
Shadowrun: Awakened 29 September 2011 - Build 871
|
00001 using System; 00002 using System.Collections.Generic; 00003 using System.Data; 00004 using System.Linq; 00005 using System.Text; 00006 using MySql.Data.MySqlClient; 00007 00008 namespace RoutineAnalyzer 00009 { 00029 class CppGetRoutine : GetRoutineBase 00030 { 00031 public CppGetRoutine(string sql) 00032 : base(sql) 00033 { 00034 } 00035 00040 public override string GetDeclaration() 00041 { 00042 StringBuilder builder = new StringBuilder(); 00043 builder.Append("static __declspec(dllexport) void "); 00044 builder.Append(ParseHelper.ConvertUnderscoreToCamelCase(_name)); 00045 builder.Append("("); 00046 foreach (RoutineParamBase param in _params) 00047 { 00048 builder.Append(param.GetDeclaration()); 00049 builder.Append(", "); 00050 } 00051 00052 builder.Append("int* queryId"); 00053 00054 builder.Append(")"); 00055 return builder.ToString(); 00056 } 00057 00058 public override string GetCode() 00059 { 00060 //start off with the declaration, then put in 00061 StringBuilder builder = new StringBuilder(); 00062 builder.AppendLine(GetDeclaration().Replace("static __declspec(dllexport) ", "")); 00063 builder.AppendLine("{"); 00064 00065 //choose to start a new stream or continue an existing one 00066 builder.AppendLine("DbStream* stream;"); 00067 builder.AppendLine("if(*queryId == DbStream::InitStreamId)"); 00068 builder.Append(" stream = DbStream::StartStream(formatString(\"CALL "); 00069 builder.Append(_name); 00070 builder.Append("(%d)\","); 00071 builder.Append(_params.First().GetPreExecuteCode()); 00072 builder.AppendLine("));"); 00073 builder.AppendLine("else"); 00074 builder.AppendLine(" stream = DbStream::RetrieveStream(queryId);"); 00075 00076 builder.AppendLine("if(stream == NULL)"); 00077 builder.AppendLine(" return;"); 00078 00079 for (int i = 1; i < _params.Count; ++i) 00080 builder.AppendLine(_params[i].GetPostExecuteCode()); 00081 00082 builder.AppendLine("if(!DbStream::CheckHasMoreRows(stream, queryId))"); 00083 builder.AppendLine(" *queryId = DbStream::InitStreamId;"); 00084 00085 //close up the statement and return it 00086 builder.Append("}"); 00087 return builder.ToString(); 00088 } 00089 00090 protected override RoutineParamBase CreateRoutineParam(string sql, int index) 00091 { 00092 return new CppGetRoutineParam(sql, index); 00093 } 00094 } 00095 }
Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.