コード例 #1
0
        static void Load(SoodaTransaction transaction)
        {
            SchemaInfo          schema          = transaction.Schema;
            HashSet <ClassInfo> affectedClasses = new HashSet <ClassInfo>();

            foreach (DataSourceInfo dsi in schema.DataSources)
            {
                if (!dsi.EnableDynamicFields)
                {
                    continue;
                }
                SoodaDataSource ds = transaction.OpenDataSource(dsi);
                using (IDataReader r = ds.ExecuteRawQuery("select class, field, type, nullable, fieldsize, precision from SoodaDynamicField"))
                {
                    while (r.Read())
                    {
                        string    className = r.GetString(0);
                        ClassInfo ci        = schema.FindClassByName(className);
                        if (ci == null)
                        {
                            logger.Warn("Ignoring a dynamic field of non-existent class {0} -- see the SoodaDynamicField table", className);
                            continue;
                        }

                        FieldInfo fi = new FieldInfo();
                        fi.ParentClass = ci;
                        fi.Name        = r.GetString(1);
                        fi.TypeName    = r.GetString(2);
                        fi.IsNullable  = r.GetInt32(3) != 0;
                        if (!r.IsDBNull(4))
                        {
                            fi.Size = r.GetInt32(4);
                        }
                        if (!r.IsDBNull(5))
                        {
                            fi.Precision = r.GetInt32(5);
                        }

                        ci.LocalTables.Add(Prepare(fi));
                        affectedClasses.Add(ci);
                    }
                }
            }

            Resolve(schema, affectedClasses);
        }
コード例 #2
0
        public void PassDbConnection()
        {
            using (SoodaDataSource sds = _DatabaseSchema.GetSchema().GetDataSourceInfo("default").CreateDataSource())
            {
                sds.Open();
                // sds.ExecuteNonQuery(sql, params);
                using (IDataReader r = sds.ExecuteRawQuery("select count(*) from contact"))
                {
                    bool b = r.Read();
                    Assert.IsTrue(b);
                    int c = r.GetInt32(0);
                    Assert.AreEqual(7, c);
                }

                using (SoodaTransaction tran = new SoodaTransaction())
                {
                    tran.RegisterDataSource(sds);

                    int c = Contact.GetList(true).Count;
                    Assert.AreEqual(7, c);
                }
            }
        }