예제 #1
0
파일: DBMapper.cs 프로젝트: x4maT/unity-orm
        public T ReadByKey <T>(object key) where T : class
        {
            var desc   = Registory.GetClassDesc <T>();
            var result = database.ExecuteQuery(
                SQLMaker.GenerateSelectSQL <T>(desc, key));

            T[] r = ResultReader.Get <T>(result, desc);
            if (r.Length > 0)
            {
                return(r[0]);
            }
            else
            {
                return(null);
            }
        }
예제 #2
0
        public void UpdateOrInsert <T>(T obj)
        {
            var    desc      = Registory.GetClassDesc <T>();
            string queryData = SQLMaker.GenerateSelectSQL <T> (desc, obj);

            try{
                DataTable queryResult = database.ExecuteQuery(queryData);

                if (queryResult.Rows.Count > 0)
                {
                    // Debug.Log(":: Update Data");
                    string update = SQLMaker.GenerateUpdateSQL(desc, obj);
                    database.ExecuteNonQuery(update);
                }
                else
                {
                    // Debug.Log(":: Insert Data");
                    string insert = SQLMaker.GenerateInsertSQL(desc, obj);
                    database.ExecuteNonQuery(insert);
                }
            }catch (SqliteException e) {
                Debug.Log("Fail! err: " + e.ErrorCode + " - " + e.Message);
            }
        }