Example #1
0
 /// <summary>
 /// Build Sql command and parameters from the shorthand fluent syntax
 /// </summary>
 /// <remarks>
 /// //Example query with multiple blocks
 /// cmd.BuildSelect(builder =>
 /// {
 ///    builder.Limit = 100;
 ///    builder.Select("T1.*").From("dbo", "TBL_USER", "T1");
 ///
 ///    builder.WhereBlockBegin(WhereClauseType.Or)
 ///           .AndWhere("T1.FIRSTNAME = ?FN1", new MySqlParameter("FN1", "Adam"))
 ///           .AndWhere("T1.FIRSTNAME != ?FN2", new MySqlParameter("FN2", "Amber"))
 ///           .WhereBlockEnd();
 ///
 ///    builder.WhereBlockBegin(WhereClauseType.Or)
 ///           .AndWhere("T1.LASTNAME = ?LN1", new MySqlParameter("LN1", "Adamson"))
 ///           .AndWhere("T1.LASTNAME != ?LN2", new MySqlParameter("LN2", "Amberman"))
 ///           .WhereBlockEnd();
 ///
 ///    builder.OrderByAsc("T1.LASTNAME")
 ///           .OrderByDesc("T1.FIRSTNAME");
 ///    builder.GroupBy("T1.FIRSTNAME");
 ///    builder.Having("T1.SCORE > ?SCORE", new MySqlParameter("SCORE", 12_000));
 ///});
 /// </remarks>
 public static MySqlCommand BuildSelect(this MySqlCrudQueryExecutionContext ctx,
                                        MySqlCommand command,
                                        Action <MySqlSelectBuilder> body)
 {
     command.NonNull(nameof(command));
     body.NonNull(nameof(body));
     using (var builder = MySqlSelectBuilder.For(ctx.DataStore.SchemaName.NonBlank("schema-name")))
     {
         body(builder);
         builder.Build(command);
     }
     return(command);
 }
Example #2
0
        /// <summary>
        /// Provides a clean instance of the builder for the specified schema.
        /// You should dispose this instance once done using .Dispose() call which returns
        /// it to the internal cache pool. Use the 'using(var builder = MySelectBuilder.For("schema"){ }' pattern
        /// </summary>
        public static MySqlSelectBuilder For(string schemaName)
        {
            var instance =
                Interlocked.Exchange(ref s_Cache1, null) ??
                Interlocked.Exchange(ref s_Cache2, null) ??
                Interlocked.Exchange(ref s_Cache3, null) ??
                Interlocked.Exchange(ref s_Cache4, null) ??
                Interlocked.Exchange(ref s_Cache5, null);

            if (instance == null)
            {
                instance = new MySqlSelectBuilder();
            }
            instance.m_SchemaName = schemaName;

            return(instance);
        }