/// <summary> /// Gets the object of data table row. /// </summary> /// <typeparam name="T">The type definition of data table row.</typeparam> /// <param name="primaryValue">The primary value.</param> /// <returns>The object of type definition.</returns> public T GetDataTableRow <T>(object primaryValue) where T : DataTableRow, new() { DataTableAddressMap addressMap = GetDatabaseAddressMap <T>(); BoxDBAdapter dbAdapter = GetDatabaseBoxAdapter(addressMap); T data = default(T); if (dbAdapter != null) { try { string tableName = addressMap.Type; dbAdapter.EnsureTable <T>(tableName, addressMap.PrimaryPropertyName); dbAdapter.Open(); data = dbAdapter.Select <T>(tableName, primaryValue); } catch (Exception exception) { Debug.LogException(exception); } finally { if (dbAdapter != null) { dbAdapter.Dispose(); } } } return(data); }
/// <summary> /// Gets the data table rows. /// </summary> /// <typeparam name="T">The type definition of data table row.</typeparam> /// <param name="conditions">The conditions.</param> /// <param name="multiConditionOperators">The multi condition operators.</param> /// <returns>The result list of data table rows.</returns> public T[] GetDataTableRows <T>(List <BoxDBQueryCondition> conditions, List <BoxDBMultiConditionOperator> multiConditionOperators = null) where T : DataTableRow, new() { DataTableAddressMap addressMap = GetDatabaseAddressMap <T>(); BoxDBAdapter dbAdapter = GetDatabaseBoxAdapter(addressMap); List <T> results = new List <T>(); if (dbAdapter != null) { try { string tableName = addressMap.Type; dbAdapter.EnsureTable <T>(tableName, addressMap.PrimaryPropertyName); dbAdapter.Open(); results = dbAdapter.Select <T>(tableName, conditions, multiConditionOperators); } catch (Exception exception) { Debug.LogException(exception); } finally { dbAdapter.Dispose(); } } return(results.ToArray()); }
public void SelectTest() { BoxDBAdapter db = GetBoxDBAdapter(); BoxDBAdapterTestVO vo = db.Select <BoxDBAdapterTestVO>(tableName, 1); Debug.Log(vo.ToString()); db.Dispose(); Assert.IsNotNull(vo); }
/// <summary> /// Gets the database address. /// </summary> /// <typeparam name="T">The type definition of data.</typeparam> /// <returns>The database address.</returns> private DataTableAddressMap GetDatabaseAddressMap <T>() { string name = typeof(T).Name; if (addressMapDBAdapter == null) { Initialize(); } DataTableAddressMap addressMap = addressMapDBAdapter.Select <DataTableAddressMap>(typeof(DataTableAddressMap).Name, name); return(addressMap); }
public void MuiltiConditionsSelectTest() { BoxDBAdapter db = GetBoxDBAdapter(); List <BoxDBQueryCondition> list = new List <BoxDBQueryCondition>() { new BoxDBQueryCondition("Id", 1), new BoxDBQueryCondition("Id", 2) }; List <BoxDBAdapterTestVO> result = db.Select <BoxDBAdapterTestVO>(tableName, list, new List <BoxDBMultiConditionOperator>(new BoxDBMultiConditionOperator[1] { BoxDBMultiConditionOperator.Or })); db.Dispose(); Assert.AreEqual(2f, result[0].Value); }
public void UpdateTest() { BoxDBAdapter db = GetBoxDBAdapter(); BoxDBAdapterTestVO[] voList = new BoxDBAdapterTestVO[3] { new BoxDBAdapterTestVO(1, "test1_update", 1f), new BoxDBAdapterTestVO(2, "测试2_update", 2f), new BoxDBAdapterTestVO(4, "test3_update", 3f) }; db.Update(tableName, voList); BoxDBAdapterTestVO vo = db.Select <BoxDBAdapterTestVO>(tableName, 1); db.Dispose(); Assert.AreEqual("test1_update", vo.Name); }