コード例 #1
0
ファイル: SQLiteAssetFetcher.cs プロジェクト: iwaag/AGAsset
        AssetUnitInfo ImmediateGiver <AssetUnitInfo, AssetUnitInfo> .PickBestElement(AssetUnitInfo key)
        {
            var sqlQueryBuilder = new System.Text.StringBuilder();

            sqlQueryBuilder.Append("SELECT * FROM assets WHERE sname = \'" + key.shortname + "\' And creatorref = \'" + key.distributor + "\'");
            bool       hasCondition = false;
            IDbCommand dbcmd        = dbconn.CreateCommand();

            dbcmd.CommandText = sqlQueryBuilder.ToString();
            IDataReader   reader       = dbcmd.ExecuteReader();
            AssetUnitInfo newAssetInfo = null;

            if (reader.Read())
            {
                newAssetInfo = EditTimeAssetUtils.EntityToAssetInfo(reader).units[0];
            }
            reader.Close();
            reader = null;
            dbcmd.Dispose();
            dbcmd = null;
            return(newAssetInfo);
        }
コード例 #2
0
ファイル: SQLiteAssetFetcher.cs プロジェクト: iwaag/AGAsset
        AssetUnitInfo RequestToAssetUnit(AssetRequestUnit reqUnit)
        {
            var sqlQueryBuilder = new System.Text.StringBuilder();

            sqlQueryBuilder.Append("SELECT * FROM assets WHERE ");
            bool   hasCondition             = false;
            Action ActionBeforeAddCondition = () => {
                if (hasCondition == false)
                {
                    hasCondition = true;
                }
                else
                {
                    sqlQueryBuilder.Append(" And ");
                }
            };

            if (reqUnit.attributes != null)
            {
                foreach (var attrbiute in reqUnit.attributes)
                {
                    ActionBeforeAddCondition();
                    sqlQueryBuilder.Append("(");
                    sqlQueryBuilder.Append("attributes = \'" + attrbiute + "\' OR ");
                    sqlQueryBuilder.Append("attributes = \'" + attrbiute + ";%\' OR ");
                    sqlQueryBuilder.Append("attributes = \'%;" + attrbiute + ";%\' OR ");
                    sqlQueryBuilder.Append("attributes = \'%;" + attrbiute + "\'");
                    sqlQueryBuilder.Append(")");
                }
            }
            if (reqUnit.assettype != null)
            {
                ActionBeforeAddCondition();
                sqlQueryBuilder.Append("assettype LIKE \'%" + reqUnit.assettype + "%\'");
            }
            if (reqUnit.creatorref != null)
            {
                ActionBeforeAddCondition();
                sqlQueryBuilder.Append("creatorref LIKE \'%" + reqUnit.creatorref + "%\'");
            }
            if (reqUnit.sname != null)
            {
                ActionBeforeAddCondition();
                sqlQueryBuilder.Append("sname LIKE \'%" + reqUnit.sname + "%\'");
            }
            IDbCommand dbcmd = dbconn.CreateCommand();

            dbcmd.CommandText = sqlQueryBuilder.ToString();
            IDataReader   reader       = dbcmd.ExecuteReader();
            AssetUnitInfo newAssetInfo = null;

            //asset found
            if (reader.Read())
            {
                newAssetInfo = EditTimeAssetUtils.EntityToAssetUnitInfo(reader);
            }
            reader.Close();
            reader = null;
            dbcmd.Dispose();
            dbcmd = null;
            return(newAssetInfo);
        }