/// <summary>
    /// 主キーを指定して該当するデータを取得する
    /// </summary>
    /// <param name="id">主キー</param>
    /// <returns>データ、ただし存在しない場合はnull</returns>
    public List <T> SelectFromPrimaryKey <U>(Dictionary <string, string> whereQuery)
    {
        StringBuilder query = new StringBuilder();

        query.Append("SELECT * FROM ");
        query.Append(TableName);

        QueryUtility.CreateWhereQuery(ref query, whereQuery);

        Debug.Log(query);
        query.Append(";");
        DataTable dt = mDb.ExecuteQuery(query.ToString());

        if (dt.Rows.Count == 0)
        {
            return(null);
        }
        else
        {
            var list = new List <T>();

            foreach (var row in dt.Rows)
            {
                list.Add(PutData(row));
            }

            return(list);
        }
    }
Ejemplo n.º 2
0
    public dynamic ExcecuteJoinQuery <T, U>(ref AbstractDbTable <T> tableT, ref AbstractDbTable <U> tableU, string joinKey, Dictionary <string, string> whereKey = null)
        where T : AbstractData where U : AbstractData
    {
        StringBuilder query = new StringBuilder();

        query.Append("SELECT");

        foreach (var select in tableT.ColAddTableName())
        {
            query.Append(select);
        }
        foreach (var select in tableU.ColAddTableName())
        {
            query.Append(select);
        }

        query.Append("FROM");
        query.Append(tableT.GetTableName());
        query.Append("LEFT OUTER JOIN");
        query.Append(tableU.GetTableName());
        query.Append("IN");
        query.Append(tableT + "." + joinKey + "=" + tableU + "." + joinKey);

        if (whereKey != null)
        {
            QueryUtility.CreateWhereQuery(ref query, whereKey);
        }

        query.Append(";");

        Debug.Log(query);

        DataTable dt = mDb.ExecuteQuery(query.ToString());

        if (dt.Rows.Count == 0)
        {
            return(null);
        }
        else
        {
            var tableTListData = new List <T>();
            var tableUListData = new List <U>();

            foreach (var row in dt.Rows)
            {
                tableTListData.Add(tableT.PutJoinData(row));
                tableUListData.Add(tableU.PutJoinData(row));
            }

            return(new
            {
                tableTListData,
                tableUListData
            });
        }
    }