Example #1
0
        private ICRUDQueryHandler searchForScript(string name)
        {
            var asm     = Assembly.Load(m_ScriptAssembly);
            var asmname = asm.FullName;
            var ic      = asmname.IndexOf(',');

            if (ic > 0)
            {
                asmname = asmname.Substring(0, ic);
            }
            var resources = asm.GetManifestResourceNames();

            name = name + m_DataStore.ScriptFileSuffix;

            var res = resources.FirstOrDefault(r => string.Equals(r, name, StringComparison.InvariantCultureIgnoreCase) ||
                                               string.Equals(r, asmname + "." + name, StringComparison.InvariantCultureIgnoreCase)
                                               );

            if (res != null)
            {
                using (var stream = asm.GetManifestResourceStream(res))
                    using (var reader = new StreamReader(stream))
                    {
                        var script  = reader.ReadToEnd();
                        var qsource = new QuerySource(name, script);
                        return(m_DataStore.MakeScriptQueryHandler(qsource));
                    }
            }
            return(null);
        }
        /// <summary>
        /// Gets schema from reader taking Query.ResultRowType in consideration
        /// </summary>
        public static Schema GetSchemaForQuery(string target, Query query, MySqlDataReader reader, QuerySource qSource, out Schema.FieldDef[] toLoad)
        {
            Schema schema;
              var rtp = query.ResultRowType;

              if (rtp != null && typeof(TypedRow).IsAssignableFrom(rtp))
                schema = Schema.GetForTypedRow(query.ResultRowType);
              else
                schema = GetSchemaFromReader(query.Name, qSource, reader);

              //determine what fields to load
              toLoad = new Schema.FieldDef[reader.FieldCount];
              for (int i = 0; i < reader.FieldCount; i++)
              {
                var name = reader.GetName(i);
                var fdef = schema[name];

              //todo A gde GetBackendNameFor target?
                if (fdef==null) continue;
                var attr =  fdef[target];
                if (attr!=null)
                {
                  if (attr.StoreFlag!=StoreFlag.LoadAndStore && attr.StoreFlag!=StoreFlag.OnlyLoad) continue;
                }
                toLoad[i] = fdef;
              }

              return schema;
        }
Example #3
0
        public CountPerzons(MongoDBDataStore store)
            : base(store, null)
        {
            m_Source = new QuerySource(GetType().FullName,
            @"#pragma
            modify=MyPerzon

            {'Age': {'$gt': '$$fromAge', '$lt': '$$toAge'}}");
        }
        /// <summary>
        /// Gets CRUD schema from MySqlReader per particular QuerySource.
        /// If source is null then all columns from reader are copied.
        /// Note: this code was purposely made provider specific because other providers may treat some nuances differently
        /// </summary>
        public static Schema GetSchemaFromReader(string name, QuerySource source, MySqlDataReader reader)
        {
            var table = name;
               var fdefs = new List<Schema.FieldDef>();

               for (int i = 0; i < reader.FieldCount; i++)
               {
                    var fname = reader.GetName(i);
                    var ftype = reader.GetFieldType(i);

                    var def = new Schema.FieldDef(fname, ftype, source!=null ? ( source.HasPragma ? source.ColumnDefs[fname] : null) : null);
                    fdefs.Add( def );
               }

               if (source!=null)
                if (source.HasPragma && source.ModifyTarget.IsNotNullOrWhiteSpace()) table = source.ModifyTarget;

               if (table.IsNullOrWhiteSpace()) table = Guid.NewGuid().ToString();

               return new Schema(table, source!=null ? source.ReadOnly : true,  fdefs);
        }
 public MongoDBCRUDQueryHandlerBase(MongoDBDataStore store, QuerySource source)
 {
     m_Store = store;
     m_Source = source;
 }
Example #6
0
    //public static readonly IErlObject EXECUTE_OK_PATTERN =
    //new ErlPatternMatcher {
    //    {"stop", (p, t, b, _args) => { active = false; return null; } },
    //    {"Msg",  (p, t, b, _args) => { Console.WriteLine(b["Msg"].ToString()); return null; } },
    //};


    #endregion
    
    #region .ctor
        public ErlCRUDScriptQueryHandler(ErlDataStore store, QuerySource source)
        {
          m_Store = store;
          m_Source = source;
        }
Example #7
0
      // Args := {trade_ctrl, stop_strat,[StratID::atom(), OpDescr::string(), User::int()]}
      // nfx_crud:rpc(ReqID, Mod, Fun, Args)
      private static parsedQuery prepareQuery(QuerySource qSource)
      {

         var src = qSource.StatementSource;

         parsedQuery result;

         if (s_ParsedQueryCache.TryGetValue(src, out result)) return result;

         try
         {
           var mfa = NFX.Erlang.ErlObject.ParseMFA(src);

           var argsTerm = mfa.Item3;
           var vars = argsTerm.Visit(new HashSet<ErlVar>(), (a, o) => { if (o is ErlVar) a.Add((ErlVar)o); return a; });

           result = new parsedQuery()
           {
             Source = src,
             Module = mfa.Item1,
             Function = mfa.Item2,
             ArgTerm = argsTerm,
             ArgVars = vars
           };
         }
         catch(Exception error)
         {
            throw new ErlDataAccessException(StringConsts.ERL_DS_QUERY_SCRIPT_PARSE_ERROR.Args(src, error.ToMessageWithType()), error);
         }

         var dict = new Dictionary<string, parsedQuery>(s_ParsedQueryCache, StringComparer.Ordinal);
         dict[src] = result;
         s_ParsedQueryCache = dict;//atomic

         return result;
      }
Example #8
0
        public void PRAGMA_1_Modifiable()
        {
            var src =
            @"#pragma
            modify=tbl_patient
            key=counter,ssn
            ignore=marker
            load=counter
            @last_name=lname
            @first_name=fname
            .last_name=This is description of last name
            invisible=marker,counter,c_doctor

            select
             1 as marker,
             t1.counter,
             t1.ssn,
             t1.lname as last_name,
             t1.fname as first_name,
             t1.c_doctor,
             t2.phone as doctor_phone,
             t2.NPI	as doctor_id
            from
             tbl_patient t1
              left outer join tbl_doctor t2 on t1.c_doctor = t2.counter
            where
             t1.lname like ?LN";

            var qs = new QuerySource("1", src);

            Assert.IsTrue( qs.HasPragma );
            Assert.IsFalse( qs.ReadOnly );
            Assert.AreEqual("tbl_patient", qs.ModifyTarget);
            Assert.AreEqual(true, qs.ColumnDefs["counter"].Key);
            Assert.AreEqual(true, qs.ColumnDefs["ssn"].Key);
            Assert.AreEqual("lname", qs.ColumnDefs["last_name"].BackendName);
            Assert.AreEqual("fname", qs.ColumnDefs["first_name"].BackendName);
            Assert.AreEqual("This is description of last name", qs.ColumnDefs["last_name"].Description);
            Assert.AreEqual(StoreFlag.OnlyLoad, qs.ColumnDefs["counter"].StoreFlag);
            Assert.AreEqual(StoreFlag.None, qs.ColumnDefs["marker"].StoreFlag);

            Assert.AreEqual(StoreFlag.LoadAndStore, qs.ColumnDefs["ssn"].StoreFlag);

            Assert.IsFalse( qs.ColumnDefs["marker"].Visible );
            Assert.IsFalse( qs.ColumnDefs["counter"].Visible );
            Assert.IsFalse( qs.ColumnDefs["c_doctor"].Visible );
            Assert.IsTrue(  qs.ColumnDefs["ssn"].Visible );
            Assert.IsTrue(  qs.ColumnDefs["last_name"].Visible );

            Assert.AreEqual(
            @"select
             1 as marker,
             t1.counter,
             t1.ssn,
             t1.lname as last_name,
             t1.fname as first_name,
             t1.c_doctor,
             t2.phone as doctor_phone,
             t2.NPI	as doctor_id
            from
             tbl_patient t1
              left outer join tbl_doctor t2 on t1.c_doctor = t2.counter
            where
             t1.lname like ?LN
            " , qs.StatementSource);
        }
Example #9
0
        public void WithoutPRAGMA_2()
        {
            var src =
            @"a123
            b
            c
            d
            e
            f
            g
            h
            j
            k";

            var qs = new QuerySource("1", src);

            Assert.IsFalse( qs.HasPragma );
            Assert.IsTrue( qs.ReadOnly );
            Assert.AreEqual("a123", qs.OriginalSource.ReadLine());
            Assert.AreEqual("a123", qs.StatementSource.ReadLine());
        }
 public MongoDBCRUDScriptQueryHandler(MongoDBDataStore store, QuerySource source)
     : base(store, source)
 {
 }
Example #11
0
            private ICRUDQueryHandler searchForScript(string name)
            {
                var asm = Assembly.Load(m_ScriptAssembly);
                var asmname = asm.FullName;
                var ic = asmname.IndexOf(',');
                if (ic>0)
                 asmname = asmname.Substring(0, ic);
                var resources = asm.GetManifestResourceNames();
                  
                name = name + m_DataStore.ScriptFileSuffix; 
                    
                var res = resources.FirstOrDefault(r => string.Equals(r, name, StringComparison.InvariantCultureIgnoreCase) ||
                                                        string.Equals(r, asmname+"."+name, StringComparison.InvariantCultureIgnoreCase)
                                                  );

                if (res!=null)
                {
                    using (var stream = asm.GetManifestResourceStream(res))
                      using (var reader = new StreamReader(stream))
                      {
                         var script = reader.ReadToEnd();
                         var qsource = new QuerySource(name, script);
                         return m_DataStore.MakeScriptQueryHandler(qsource);
                      }
                }
                return null;
            }
 public MySQLCRUDScriptQueryHandler(MySQLDataStore store, QuerySource source)
 {
     m_Store = store;
         m_Source = source;
 }
        /// <summary>
        /// Reads data from reader into rowset. the reader is NOT disposed
        /// </summary>
        public static Rowset PopulateRowset(MySQLCRUDQueryExecutionContext context, MySqlDataReader reader, string target, Query query, QuerySource qSource, bool oneRow)
        {
            Schema.FieldDef[] toLoad;
              Schema schema = GetSchemaForQuery(target, query, reader, qSource, out toLoad);
              var store= context.DataStore;

              var result = new Rowset(schema);
              while(reader.Read())
              {
                var row = PopulateRow(context, query.ResultRowType, schema, toLoad, reader);

                result.Add( row );
                if (oneRow) break;
              }

              return result;
        }
Example #14
0
 protected CRUDQueryHandler(ICRUDDataStore store, QuerySource source) : this(store, source.NonNull().Name)
 {
     Source = source;
 }
Example #15
0
 public ICRUDQueryHandler MakeScriptQueryHandler(QuerySource querySource)
 {
     return new MySQLCRUDScriptQueryHandler(this, querySource);
 }
Example #16
0
        public void WithoutPRAGMA_1()
        {
            var src = "abc";

            var qs = new QuerySource("1", src);

            Assert.IsFalse( qs.HasPragma );
            Assert.IsTrue( qs.ReadOnly );
            Assert.AreEqual("abc", qs.OriginalSource);
            Assert.AreEqual("abc", qs.StatementSource);
        }
 public ICRUDQueryHandler MakeScriptQueryHandler(QuerySource querySource)
 {
     throw new NotImplementedException();
 }
 public ICRUDQueryHandler MakeScriptQueryHandler(QuerySource querySource)
 {
     throw new NotImplementedException();
 }