예제 #1
0
        public NexusExtDBResult Insert(string table, JToken row)
        {
            List <string> columns = new List <string>();
            List <object> values  = new List <object>();

            foreach (JProperty prop in row)
            {
                columns.Add(prop.Name);
                values.Add(((JValue)prop.Value).Value);
            }

            sql.INSERT_INTO(string.Format("{0}({1})", table, string.Join(", ", columns))).VALUES(values);

            NexusExtDBResult result = new NexusExtDBResult();

            try {
                db.Execute(sql);
                result.Inserted = 1;
                result.GeneratedKeys.Add(db.LastInsertId());
            }
            catch (Exception e) {
                result.Errors     = 1;
                result.FirstError = e.Message;
            }

            return(result);
        }
예제 #2
0
        public override void InnerRun(Dictionary <string, object> vars, Dictionary <string, object> outputVars, Dictionary <string, object> InvertedInputVars, Message message)
        {
            COREobject core    = COREobject.i;
            DBEntities context = core.Context;

            try
            {
                string dbName    = (string)vars["dbName"];
                string tableName = (string)vars["TableName"];
                JToken data      = (JToken)vars["Data"];
                object where = (object)vars["Where"];

                if (where == null || (where is String && string.IsNullOrEmpty((string)where)))
                {
                    throw new Exception(string.Format("{0}: where is missing. You must provide where clausule or rethingDB item id", Name));
                }

                ExtDB dbInfo = context.ExtDBs.Where(d => d.DB_Alias == dbName).SingleOrDefault();
                if (dbInfo == null)
                {
                    throw new Exception(string.Format("{0}: Integration was not found", Name));
                }

                NexusExtDBBaseService service;
                switch (dbInfo.DB_Type)
                {
                case ExtDBType.RethinkDB:
                    service = new NexusExtDBRethingService(dbInfo);
                    break;

                default:
                    service = (new NexusExtDBService(dbInfo.DB_Server, dbInfo.DB_Alias)).NewQuery("");
                    break;
                }

                NexusExtDBResult result = service.Update(tableName, data, where);

                if (result.Errors == 0)
                {
                    outputVars["Result"] = result.Replaced;
                    outputVars["Error"]  = false;
                }
                else
                {
                    outputVars["Result"] = result.FirstError;
                    outputVars["Error"]  = true;

                    OmniusException.Log(result.FirstError, OmniusLogSource.Nexus, null, core.Application, core.User);
                }
            }
            catch (Exception e)
            {
                string errorMsg = e.Message;
                OmniusException.Log(e, OmniusLogSource.Nexus, core.Application, core.User);
                outputVars["Result"] = String.Empty;
                outputVars["Error"]  = true;
            }
        }
예제 #3
0
        public override void InnerRun(Dictionary <string, object> vars, Dictionary <string, object> outputVars, Dictionary <string, object> InvertedInputVars, Message message)
        {
            COREobject core    = COREobject.i;
            DBEntities context = core.Context;

            try
            {
                string dbName    = (string)vars["dbName"];
                string tableName = (string)vars["TableName"];
                JToken data      = (JToken)vars["Data"];

                ExtDB dbInfo = context.ExtDBs.Where(d => d.DB_Alias == dbName).SingleOrDefault();
                if (dbInfo == null)
                {
                    throw new Exception(string.Format("{0}: Integration was not found", Name));
                }

                NexusExtDBBaseService service;
                switch (dbInfo.DB_Type)
                {
                case ExtDBType.RethinkDB:
                    service = new NexusExtDBRethingService(dbInfo);
                    break;

                default:
                    service = (new NexusExtDBService(dbInfo.DB_Server, dbInfo.DB_Alias)).NewQuery("");
                    break;
                }

                NexusExtDBResult result = service.Insert(tableName, data);

                if (result.Errors == 0)
                {
                    outputVars["Result"] = result.GeneratedKeys.Count > 0 ? result.GeneratedKeys[0] : "";
                    outputVars["Error"]  = false;
                }
                else
                {
                    outputVars["Result"] = result.FirstError;
                    outputVars["Error"]  = true;

                    OmniusException.Log(result.FirstError, OmniusLogSource.Nexus, null, core.Application, core.User);
                }
            }
            catch (Exception e)
            {
                OmniusException.Log(e, OmniusLogSource.Nexus, core.Application, core.User);
                outputVars["Result"] = String.Empty;
                outputVars["Error"]  = true;
            }
        }
예제 #4
0
        public NexusExtDBResult Delete(string table, object id)
        {
            sql = sql.DELETE_FROM(table);
            sql = sql.WHERE((string)id);

            NexusExtDBResult result = new NexusExtDBResult();

            try {
                int affected = db.Execute(sql);
                result.Deleted = (ulong)affected;
            }
            catch (Exception e) {
                result.Errors     = 1;
                result.FirstError = e.Message;
            }

            return(result);
        }
예제 #5
0
        public NexusExtDBResult Update(string table, JToken row, object id)
        {
            sql = sql.UPDATE(table);
            foreach (JProperty prop in row)
            {
                sql = sql.SET($"{prop.Name} = {0}", ((JValue)prop.Value).Value);
            }
            sql = sql.WHERE((string)id);

            NexusExtDBResult result = new NexusExtDBResult();

            try {
                int affected = db.Execute(sql);
                result.Replaced = (ulong)affected;
            }
            catch (Exception e) {
                result.Errors     = 1;
                result.FirstError = e.Message;
            }

            return(result);
        }