コード例 #1
0
ファイル: SchemaProvider.cs プロジェクト: BjkGkh/R106
 private string GetSqlMode()
 {
     MySqlCommand cmd = new MySqlCommand("SELECT @@SQL_MODE", connection);
       return cmd.ExecuteScalar().ToString();
 }
コード例 #2
0
ファイル: MySqlHelper.cs プロジェクト: BjkGkh/R106
    /// <summary>
    /// Execute a single command against a MySQL database.
    /// </summary>
    /// <param name="connection"><see cref="MySqlConnection"/> object to use</param>
    /// <param name="commandText">Command text to use for the command</param>
    /// <param name="commandParameters">Parameters to use for the command</param>
    /// <returns>The first column of the first row in the result set, or a null reference if the result set is empty.</returns>
    public static object ExecuteScalar(MySqlConnection connection, string commandText, params MySqlParameter[] commandParameters)
    {
      //create a command and prepare it for execution
      MySqlCommand cmd = new MySqlCommand();
      cmd.Connection = connection;
      cmd.CommandText = commandText;
      cmd.CommandType = CommandType.Text;

      if (commandParameters != null)
        foreach (MySqlParameter p in commandParameters)
          cmd.Parameters.Add(p);

      //execute the command & return the results
      object retval = cmd.ExecuteScalar();

      // detach the SqlParameters from the command object, so they can be used again.
      cmd.Parameters.Clear();
      return retval;

    }
コード例 #3
0
ファイル: Connection.cs プロジェクト: BjkGkh/R106
		internal string CurrentDatabase()
		{
			if (Database != null && Database.Length > 0)
				return Database;
			MySqlCommand cmd = new MySqlCommand("SELECT database()", this);
			return cmd.ExecuteScalar().ToString();
		}
コード例 #4
0
ファイル: command.cs プロジェクト: BjkGkh/R106
        internal string GetCommandTextForBatching()
        {
            if (batchableCommandText == null)
              {
            // if the command starts with insert and is "simple" enough, then
            // we can use the multi-value form of insert
            if (String.Compare(CommandText.Substring(0, 6), "INSERT", true) == 0)
            {
              MySqlCommand cmd = new MySqlCommand("SELECT @@sql_mode", Connection);
              string sql_mode = cmd.ExecuteScalar().ToString().ToUpper(CultureInfo.InvariantCulture);
              MySqlTokenizer tokenizer = new MySqlTokenizer(CommandText);
              tokenizer.AnsiQuotes = sql_mode.IndexOf("ANSI_QUOTES") != -1;
              tokenizer.BackslashEscapes = sql_mode.IndexOf("NO_BACKSLASH_ESCAPES") == -1;
              string token = tokenizer.NextToken().ToLower(CultureInfo.InvariantCulture);
              while (token != null)
              {
            if (token.ToUpper(CultureInfo.InvariantCulture) == "VALUES" &&
                !tokenizer.Quoted)
            {
              token = tokenizer.NextToken();
              Debug.Assert(token == "(");

              // find matching right paren, and ensure that parens
              // are balanced.
              int openParenCount = 1;
              while (token != null)
              {
                batchableCommandText += token;
                token = tokenizer.NextToken();

                if (token == "(")
                  openParenCount++;
                else if (token == ")")
                  openParenCount--;

                if (openParenCount == 0)
                  break;
              }

              if (token != null)
                batchableCommandText += token;
              token = tokenizer.NextToken();
              if (token != null && (token == "," ||
                  token.ToUpper(CultureInfo.InvariantCulture) == "ON"))
              {
                batchableCommandText = null;
                break;
              }
            }
            token = tokenizer.NextToken();
              }
            }
            // Otherwise use the command verbatim
            else batchableCommandText = CommandText;
              }

              return batchableCommandText;
        }
コード例 #5
0
ファイル: Driver.cs プロジェクト: BjkGkh/R106
 private int GetTimeZoneOffset( MySqlConnection con )
 {
   MySqlCommand cmd = new MySqlCommand("select timediff( curtime(), utc_time() )", con);
   string s = cmd.ExecuteScalar().ToString();
   return int.Parse(s.Substring(0, s.IndexOf(':') ));
 }