Exemplo n.º 1
0
        /// <summary>
        /// Selects the data list by some conditions.
        /// </summary>
        /// <typeparam name="T">The type of data.</typeparam>
        /// <param name="tableName">Name of the table.</param>
        /// <param name="conditions">The conditions.</param>
        /// <returns></returns>
        public List <T> Select <T>(string tableName, Dictionary <string, object> conditions) where T : class, new()
        {
            try
            {
                using (m_db.Cube())
                {
                    string sql    = "from " + tableName + " where";
                    int    i      = 0;
                    int    length = conditions.Keys.Count;

                    foreach (string key in conditions.Keys)
                    {
                        sql += " " + key + "==?";

                        if (i < length - 1)
                        {
                            sql += " &";
                        }

                        i++;
                    }

                    List <object>    values = new List <object>(conditions.Values);
                    IBEnumerable <T> items  = m_db.Select <T>(sql, values.ToArray());
                    return(new List <T>(items));
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the configuration metadata list.
        /// </summary>
        /// <typeparam name="T">The type of metadata.</typeparam>
        /// <param name="conditions">The conditions dictionary.</param>
        /// <returns></returns>
        public List <T> GetConfigMetadataList <T>(Dictionary <string, object> conditions) where T : ConfigMetadata, new()
        {
            DB.AutoBox db = GetDB <T>();

            if (db != null)
            {
                Type   type      = typeof(T);
                string tableName = type.Name;
                string sql       = "from " + tableName + " where";

                int i      = 0;
                int length = conditions.Keys.Count;

                foreach (string key in conditions.Keys)
                {
                    sql += " " + key + "==?";

                    if (i < length - 1)
                    {
                        sql += " &";
                    }

                    i++;
                }

                List <object>    values = new List <object>(conditions.Values);
                IBEnumerable <T> items  = db.Select <T>(sql, values.ToArray());
                return(new List <T>(items));
            }

            return(null);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Retrieve all data items of the table.
        /// </summary>
        /// <typeparam name="T">The tyoe of data return.</typeparam>
        /// <param name="tableName">Name of the table.</param>
        /// <returns>All data items of the table.</returns>
        public List <T> SelectAll <T>(string tableName) where T : class, new()
        {
            try
            {
                if (database != null)
                {
                    object[] values;
                    string   sql = GenerateMultiConditionQuerySQL(out values, tableName);

                    if (!string.IsNullOrEmpty(sql))
                    {
                        IBEnumerable <T> items = database.Select <T>(sql, values);
                        return(new List <T>(items));
                    }
                }
            }
            catch (Exception exception)
            {
                Debug.LogException(exception);
            }

            return(null);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets the table local address.
        /// </summary>
        /// <typeparam name="T">The type of object.</typeparam>
        /// <returns>The local address of table.</returns>
        private long GetTableLocalAddress <T>() where T : ConfigMetadata
        {
            if (m_tableIndexDB == null)
            {
                CreateTableIndexDB();
            }

            Type   type = typeof(T);
            string sql  = string.Format("from {0} where typeNamespace==? & typeName==?", MetadataLocalAddress.TableName);
            IBEnumerable <MetadataLocalAddress> items = m_tableIndexDB.Select <MetadataLocalAddress>(sql, type.Namespace, type.Name);

            if (items != null)
            {
                List <MetadataLocalAddress> list = new List <MetadataLocalAddress>(items);

                if (list.Count > 0)
                {
                    return(list[0].localAddress);
                }
            }

            return(-1);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Retrieve the data items by some conditions.
        /// </summary>
        /// <typeparam name="T">The tyoe of data return.</typeparam>
        /// <param name="tableName">Name of the table.</param>
        /// <param name="conditions">The query conditions.</param>
        /// <param name="multiConditionOperators">The multi-condition operators.</param>
        /// <returns>The data items.</returns>
        public List <T> Select <T>(string tableName, List <BoxDBQueryCondition> conditions,
                                   List <BoxDBMultiConditionOperator> multiConditionOperators = null) where T : class, new()
        {
            try
            {
                if (database != null)
                {
                    object[] values;
                    string   sql = GenerateMultiConditionQuerySQL(out values, tableName, conditions, multiConditionOperators);

                    if (!string.IsNullOrEmpty(sql))
                    {
                        IBEnumerable <T> items = database.Select <T>(sql, values);
                        return(new List <T>(items));
                    }
                }
            }
            catch (Exception exception)
            {
                DebugLogger.LogException(exception, this);
            }

            return(null);
        }