Beispiel #1
0
 private List<ScriptStatement> BreakIntoStatements(bool ansiQuotes, bool noBackslashEscapes)
 {
     int startIndex = 0;
     List<ScriptStatement> list = new List<ScriptStatement>();
     List<int> lineNumbers = this.BreakScriptIntoLines();
     SqlTokenizer tokenizer = new SqlTokenizer(this.query);
     tokenizer.AnsiQuotes = ansiQuotes;
     tokenizer.BackslashEscapes = !noBackslashEscapes;
     for (string str = tokenizer.NextToken(); str != null; str = tokenizer.NextToken())
     {
         if (!tokenizer.Quoted && !tokenizer.IsSize)
         {
             int index = str.IndexOf(this.Delimiter);
             if (index != -1)
             {
                 int num3 = (tokenizer.Index - str.Length) + index;
                 if (tokenizer.Index == (this.query.Length - 1))
                 {
                     num3++;
                 }
                 string str2 = this.query.Substring(startIndex, num3 - startIndex);
                 ScriptStatement item = new ScriptStatement();
                 item.text = str2.Trim();
                 item.line = this.FindLineNumber(startIndex, lineNumbers);
                 item.position = startIndex - lineNumbers[item.line];
                 list.Add(item);
                 startIndex = num3 + this.delimiter.Length;
             }
         }
     }
     if (tokenizer.Index > startIndex)
     {
         string str3 = this.query.Substring(startIndex).Trim();
         if (!string.IsNullOrEmpty(str3))
         {
             ScriptStatement statement2 = new ScriptStatement();
             statement2.text = str3;
             statement2.line = this.FindLineNumber(startIndex, lineNumbers);
             statement2.position = startIndex - lineNumbers[statement2.line];
             list.Add(statement2);
         }
     }
     return list;
 }
Beispiel #2
0
 private void ParseProcedureBody(DataTable parametersTable, string body, DataRow row, string nameToRestrict)
 {
     string str2;
     ArrayList list = new ArrayList(new string[] { "IN", "OUT", "INOUT" });
     string str = row["SQL_MODE"].ToString();
     int num = 1;
     SqlTokenizer tokenizer = new SqlTokenizer(body);
     tokenizer.AnsiQuotes = str.IndexOf("ANSI_QUOTES") != -1;
     tokenizer.BackslashEscapes = str.IndexOf("NO_BACKSLASH_ESCAPES") == -1;
     for (str2 = tokenizer.NextToken(); str2 != "("; str2 = tokenizer.NextToken())
     {
         if ((string.Compare(str2, "FUNCTION", true) == 0) && (nameToRestrict == null))
         {
             parametersTable.Rows.Add(parametersTable.NewRow());
             InitParameterRow(row, parametersTable.Rows[0]);
         }
     }
     str2 = tokenizer.NextToken();
     while (str2 != ")")
     {
         DataRow parameter = parametersTable.NewRow();
         InitParameterRow(row, parameter);
         parameter["ORDINAL_POSITION"] = num++;
         string item = str2.ToUpper(CultureInfo.InvariantCulture);
         if (!tokenizer.Quoted && list.Contains(item))
         {
             parameter["PARAMETER_MODE"] = item;
             str2 = tokenizer.NextToken();
         }
         parameter["PARAMETER_NAME"] = str2;
         str2 = this.ParseDataType(parameter, tokenizer);
         if (str2 == ",")
         {
             str2 = tokenizer.NextToken();
         }
         if ((nameToRestrict == null) || (string.Compare(parameter["PARAMETER_NAME"].ToString(), nameToRestrict, true) == 0))
         {
             parametersTable.Rows.Add(parameter);
         }
     }
     if (string.Compare(tokenizer.NextToken().ToLower(CultureInfo.InvariantCulture), "returns", true) == 0)
     {
         DataRow row3 = parametersTable.Rows[0];
         row3["PARAMETER_NAME"] = "RETURN_VALUE";
         this.ParseDataType(row3, tokenizer);
     }
 }
Beispiel #3
0
 private string GetProcedureParameterLine(DataRow isRow)
 {
     string format = "SHOW CREATE {0} `{1}`.`{2}`";
     MySqlCommand command = new MySqlCommand(string.Format(format, isRow["ROUTINE_TYPE"], isRow["ROUTINE_SCHEMA"], isRow["ROUTINE_NAME"]), base.connection);
     using (MySqlDataReader reader = command.ExecuteReader())
     {
         string str4;
         reader.Read();
         if (reader.IsDBNull(2))
         {
             return null;
         }
         string str2 = reader.GetString(1);
         string input = reader.GetString(2);
         SqlTokenizer tokenizer = new SqlTokenizer(input);
         tokenizer.AnsiQuotes = str2.IndexOf("ANSI_QUOTES") != -1;
         tokenizer.BackslashEscapes = str2.IndexOf("NO_BACKSLASH_ESCAPES") == -1;
         for (str4 = tokenizer.NextToken(); str4 != "("; str4 = tokenizer.NextToken())
         {
         }
         int startIndex = tokenizer.Index + 1;
         str4 = tokenizer.NextToken();
         while ((str4 != ")") || tokenizer.Quoted)
         {
             str4 = tokenizer.NextToken();
             if ((str4 == "(") && !tokenizer.Quoted)
             {
                 while ((str4 != ")") || tokenizer.Quoted)
                 {
                     str4 = tokenizer.NextToken();
                 }
                 str4 = tokenizer.NextToken();
             }
         }
         return input.Substring(startIndex, tokenizer.Index - startIndex);
     }
 }
Beispiel #4
0
 private string ParseDataType(DataRow row, SqlTokenizer tokenizer)
 {
     StringBuilder builder = new StringBuilder(tokenizer.NextToken().ToUpper(CultureInfo.InvariantCulture));
     row["DATA_TYPE"] = builder.ToString();
     string type = row["DATA_TYPE"].ToString();
     string size = tokenizer.NextToken();
     if (tokenizer.IsSize)
     {
         builder.AppendFormat(CultureInfo.InvariantCulture, "({0})", new object[] { size });
         if ((type != "ENUM") && (type != "SET"))
         {
             ParseDataTypeSize(row, size);
         }
         size = tokenizer.NextToken();
     }
     else
     {
         builder.Append(GetDataTypeDefaults(type, row));
     }
     while (((size != ")") && (size != ",")) && (string.Compare(size, "begin", true) != 0))
     {
         if ((string.Compare(size, "CHARACTER", true) != 0) && (string.Compare(size, "BINARY", true) != 0))
         {
             if ((string.Compare(size, "SET", true) == 0) || (string.Compare(size, "CHARSET", true) == 0))
             {
                 row["CHARACTER_SET_NAME"] = tokenizer.NextToken();
             }
             else if (string.Compare(size, "ASCII", true) == 0)
             {
                 row["CHARACTER_SET_NAME"] = "latin1";
             }
             else if (string.Compare(size, "UNICODE", true) == 0)
             {
                 row["CHARACTER_SET_NAME"] = "ucs2";
             }
             else if (string.Compare(size, "COLLATE", true) == 0)
             {
                 row["COLLATION_NAME"] = tokenizer.NextToken();
             }
             else
             {
                 builder.AppendFormat(CultureInfo.InvariantCulture, " {0}", new object[] { size });
             }
         }
         size = tokenizer.NextToken();
     }
     if (builder.Length > 0)
     {
         row["DTD_IDENTIFIER"] = builder.ToString();
     }
     if (row["COLLATION_NAME"].ToString().Length == 0)
     {
         row["COLLATION_NAME"] = CharSetMap.GetDefaultCollation(row["CHARACTER_SET_NAME"].ToString(), base.connection);
     }
     if (row["CHARACTER_MAXIMUM_LENGTH"] != DBNull.Value)
     {
         row["CHARACTER_OCTET_LENGTH"] = CharSetMap.GetMaxLength(row["CHARACTER_SET_NAME"].ToString(), base.connection) * ((int) row["CHARACTER_MAXIMUM_LENGTH"]);
     }
     return size;
 }
Beispiel #5
0
 private ArrayList TokenizeSql2(string sql)
 {
     ArrayList list = new ArrayList();
     StringBuilder builder = new StringBuilder();
     bool flag = this.Connection.Settings.AllowBatch & this.Driver.SupportsBatch;
     int startIndex = 0;
     SqlTokenizer tokenizer = new SqlTokenizer(sql);
     string str = this.Connection.driver.Property("sql_mode");
     if (str != null)
     {
         str = str.ToString().ToLower();
         tokenizer.AnsiQuotes = str.IndexOf("ansi_quotes") != -1;
         tokenizer.BackslashEscapes = str.IndexOf("no_backslash_escapes") == -1;
     }
     for (string str2 = tokenizer.NextToken(); str2 != null; str2 = tokenizer.NextToken())
     {
         if ((str2 == ";") && !flag)
         {
             list.Add(builder.ToString());
             builder.Remove(0, builder.Length);
         }
         else if ((str2.Length >= 2) && (((str2[0] == '@') && (str2[1] != '@')) || (str2[0] == '?')))
         {
             list.Add(builder.ToString());
             builder.Remove(0, builder.Length);
         }
         else
         {
             builder.Append(sql.Substring(startIndex, (tokenizer.Index - startIndex) + 1));
             startIndex = tokenizer.Index;
         }
     }
     if (builder.Length > 0)
     {
         list.Add(builder.ToString());
     }
     return list;
 }
Beispiel #6
0
		internal string GetCommandTextForBatching() {
			if( this.batchableCommandText == null ) {
				if( string.Compare( this.CommandText.Substring( 0, 6 ), "INSERT", true ) == 0 ) {
					MySqlCommand command = new MySqlCommand( "SELECT @@sql_mode", this.Connection );
					string str = command.ExecuteScalar().ToString().ToLower( CultureInfo.InvariantCulture );
					SqlTokenizer tokenizer = new SqlTokenizer( this.CommandText );
					tokenizer.AnsiQuotes = str.IndexOf( "ansi_quotes" ) != -1;
					tokenizer.BackslashEscapes = str.IndexOf( "no_backslash_escapes" ) == -1;
					for( string str2 = tokenizer.NextToken().ToLower( CultureInfo.InvariantCulture ); str2 != null; str2 = tokenizer.NextToken() ) {
						if( ( str2.ToLower( CultureInfo.InvariantCulture ) == "values" ) && !tokenizer.Quoted ) {
							str2 = tokenizer.NextToken();
							while( ( str2 != null ) && ( str2 != ")" ) ) {
								this.batchableCommandText = this.batchableCommandText + str2;
								str2 = tokenizer.NextToken();
							}
							if( str2 != null ) {
								this.batchableCommandText = this.batchableCommandText + str2;
							}
							str2 = tokenizer.NextToken();
							if( ( str2 != null ) && ( ( str2 == "," ) || ( str2.ToLower( CultureInfo.InvariantCulture ) == "on" ) ) ) {
								this.batchableCommandText = null;
								break;
							}
						}
					}
				}
				if( this.batchableCommandText == null ) {
					this.batchableCommandText = this.CommandText;
				}
			}
			return this.batchableCommandText;
		}
Beispiel #7
0
 private void ParseConstraint(DataTable fkTable, DataRow table, SqlTokenizer tokenizer, bool includeColumns)
 {
     string str = tokenizer.NextToken();
     DataRow row = fkTable.NewRow();
     string str2 = tokenizer.NextToken();
     if ((str2 == "foreign") && !tokenizer.Quoted)
     {
         tokenizer.NextToken();
         tokenizer.NextToken();
         row["CONSTRAINT_CATALOG"] = table["TABLE_CATALOG"];
         row["CONSTRAINT_SCHEMA"] = table["TABLE_SCHEMA"];
         row["TABLE_CATALOG"] = table["TABLE_CATALOG"];
         row["TABLE_SCHEMA"] = table["TABLE_SCHEMA"];
         row["TABLE_NAME"] = table["TABLE_NAME"];
         row["REFERENCED_TABLE_CATALOG"] = null;
         row["CONSTRAINT_NAME"] = str;
         ArrayList srcColumns = includeColumns ? this.ParseColumns(tokenizer) : null;
         while ((str2 != "references") || tokenizer.Quoted)
         {
             str2 = tokenizer.NextToken();
         }
         string str3 = tokenizer.NextToken();
         string str4 = tokenizer.NextToken();
         if (str4.StartsWith("."))
         {
             row["REFERENCED_TABLE_SCHEMA"] = str3;
             row["REFERENCED_TABLE_NAME"] = str4.Substring(1);
             tokenizer.NextToken();
         }
         else
         {
             row["REFERENCED_TABLE_SCHEMA"] = table["TABLE_SCHEMA"];
             row["REFERENCED_TABLE_NAME"] = str3;
         }
         ArrayList targetColumns = includeColumns ? this.ParseColumns(tokenizer) : null;
         if (includeColumns)
         {
             this.ProcessColumns(fkTable, row, srcColumns, targetColumns);
         }
         else
         {
             fkTable.Rows.Add(row);
         }
     }
 }
Beispiel #8
0
 private ArrayList ParseColumns(SqlTokenizer tokenizer)
 {
     ArrayList list = new ArrayList();
     for (string str = tokenizer.NextToken(); str != ")"; str = tokenizer.NextToken())
     {
         if (str != ",")
         {
             list.Add(str);
         }
     }
     return list;
 }
Beispiel #9
0
 private void GetForeignKeysOnTable(DataTable fkTable, DataRow tableToParse, string filterName, bool includeColumns)
 {
     string sqlMode = this.GetSqlMode();
     if (filterName != null)
     {
         filterName = filterName.ToLower(CultureInfo.InvariantCulture);
     }
     string cmdText = string.Format("SHOW CREATE TABLE `{0}`.`{1}`", tableToParse["TABLE_SCHEMA"], tableToParse["TABLE_NAME"]);
     string input = null;
     MySqlCommand command = new MySqlCommand(cmdText, this.connection);
     using (MySqlDataReader reader = command.ExecuteReader())
     {
         reader.Read();
         input = reader.GetString(1).ToLower(CultureInfo.InvariantCulture);
     }
     SqlTokenizer tokenizer = new SqlTokenizer(input);
     tokenizer.AnsiQuotes = sqlMode.IndexOf("ANSI_QUOTES") != -1;
     tokenizer.BackslashEscapes = sqlMode.IndexOf("NO_BACKSLASH_ESCAPES") != -1;
     while (true)
     {
         string str5 = tokenizer.NextToken();
         while ((str5 != null) && ((str5 != "constraint") || tokenizer.Quoted))
         {
             str5 = tokenizer.NextToken();
         }
         if (str5 == null)
         {
             return;
         }
         this.ParseConstraint(fkTable, tableToParse, tokenizer, includeColumns);
     }
 }