public string ResultToStringForStatement(string databaseStatement) { DatabaseRecordSet recordSet = new DatabaseRecordSet(this.Database); int ret = recordSet.Execute(databaseStatement); StringBuilder resultString = new StringBuilder(); if (ret == 0) { for (int i = 0; i < recordSet.GetColumnCount(); i++) { resultString.Append(i == 0 ? recordSet.GetColumnName(0) : $";{recordSet.GetColumnName(i)}"); } resultString.AppendLine(); for (int i = 0; i < recordSet.GetRowCount(); i++) { DatabaseRow row = recordSet.GetRow(i); for (int j = 0; j < recordSet.GetColumnCount(); j++) { resultString.Append(j == 0 ? row.GetColumn(0) : $";{row.GetColumn(j)}"); } resultString.AppendLine(); } } return(resultString.ToString()); }
/// <summary> /// Offlines the records for request. /// </summary> /// <returns></returns> public List <string> OfflineRecordsForRequest() { List <string> deleteRecordArray = null; IDatabase database = this.Storage.Database; database.BeginTransaction(); DatabaseRecordSet recordSet = new DatabaseRecordSet(database); if (recordSet.Query.Prepare("SELECT infoAreaid, recordid FROM records WHERE requestnr = ? AND mode = 'NewOffline'")) { recordSet.Query.Bind(1, (int)this.RequestNr); int ret = recordSet.Execute(); if (ret == 0) { int count = recordSet.GetRowCount(); if (count > 0) { deleteRecordArray = new List <string>(); for (int i = 0; i < count; i++) { DatabaseRow row = recordSet.GetRow(i); deleteRecordArray.Add($"{row.GetColumn(0)}.{row.GetColumn(1)}"); } } } } database.Commit(); return(deleteRecordArray); }
/// <summary> /// Loads from database. /// </summary> /// <param name="database">The database.</param> /// <returns> /// True if success, else false /// </returns> public override bool LoadFromDatabase(IDatabase database) { if (!base.LoadFromDatabase(database)) { return(false); } int ret = 0; DatabaseRecordSet recordSet = new DatabaseRecordSet(database); if (recordSet.Query.Prepare("SELECT data, filename, mimetype, infoareaid, recordid, fieldid FROM documentuploads WHERE requestnr = ?")) { recordSet.Query.Bind(1, this.RequestNr); ret = recordSet.Execute(); if (ret == 0) { int count = recordSet.GetRowCount(); if (count == 1) { DatabaseRow row = recordSet.GetRow(0); string databaseValue = row.GetColumn(0); if (databaseValue.StartsWith("file://")) { string lastPathComponent = databaseValue.StartsWith("file://localhost") ? Path.GetFileName(databaseValue) : databaseValue.Substring(7); this.LocalFileUrl = this.Storage.GetOfflineStoragePath(lastPathComponent); Task <byte[]> t = SimpleIoc.Default.GetInstance <IPlatformService>().StorageProvider.FileContents(this.LocalFileUrl); this.Data = t.Result; if (SimpleIoc.Default.GetInstance <ILogSettings>().LogUpSync) { SimpleIoc.Default.GetInstance <ILogger>().LogDebug($"Sync request {this.RequestNr}: document {this.LocalFileUrl} loaded ({this.Data.Length} bytes)", LogFlag.LogUpSync); } } else { this.LocalFileUrl = null; this.Data = Convert.FromBase64String(databaseValue); } this.FileName = row.GetColumn(1); this.MimeType = row.GetColumn(2); string infoAreaId = row.GetColumn(3); string recordId = row.GetColumn(4); this.RecordIdentification = StringExtensions.InfoAreaIdRecordId(infoAreaId, recordId); this.FieldId = row.GetColumnInt(5); } } } return(ret == 0 && this.Data != null); }
/// <summary> /// Requests from result row. /// </summary> /// <param name="row">The row.</param> /// <returns></returns> public UPOfflineRequest RequestFromResultRow(DatabaseRow row) { var col = row.GetColumnInt(0); var col1 = row.GetColumn(1); var col2 = row.GetColumn(2); if (col1 == null || col2 == null) { return(null); } return(this.RequestWithNrTypeProcessType(col, (OfflineRequestType)Enum.Parse(typeof(OfflineRequestType), col1), (OfflineRequestProcess)Enum.Parse(typeof(OfflineRequestProcess), col2))); }
/// <summary> /// Loads this instance. /// </summary> /// <returns></returns> private int Load() { CRMDatabase database = this.DataStore.DatabaseInstance; DatabaseRecordSet recordSet = new DatabaseRecordSet(database); int ret = recordSet.Execute("SELECT infoareaid, recordid, rollbackinfo FROM rollbackinfo WHERE requestnr = ?", this.RequestId); if (ret != 0) { return(ret); } int rowCount = recordSet.GetRowCount(); for (int i = 0; i < rowCount; i++) { DatabaseRow row = recordSet.GetRow(i); string recordIdentification = $"{row.GetColumn(0)}.{row.GetColumn(1)}"; var rollbackinfo = row.GetColumn(2); this.AddRecordIdentificationRollbackInfo(recordIdentification, rollbackinfo); } return(0); }
/// <summary> /// Checks the update before cache save with database. /// </summary> /// <param name="database">The database.</param> /// <returns>0, if success, else error number</returns> private int CheckUpdateBeforeCacheSaveWithDatabase(DatabaseBase database) { UPCRMTableInfo tableInfo = this.UndoRequest.DataStore.TableInfoForInfoArea(this.RecordIdentification.InfoAreaId()); StringBuilder selectStatement = new StringBuilder(); selectStatement.Append("SELECT "); bool first = true; List <string> allColumns = this.FieldDictionary.Keys.ToList(); foreach (string columnName in allColumns) { if (first) { first = false; } else { selectStatement.Append(", "); } selectStatement.Append(columnName); } if (first) { selectStatement.Append("recid"); } selectStatement.Append($" FROM {tableInfo.DatabaseTableName} WHERE recid = ?"); CRMDatabase db = this.UndoRequest.DataStore.DatabaseInstance; DatabaseRecordSet rs = new DatabaseRecordSet(db); if (!rs.Query.Prepare(selectStatement.ToString())) { return(-1); } rs.Query.Bind(1, this.RecordIdentification.RecordId()); int ret = rs.Execute(); if (ret != 0) { return(ret); } int rc = rs.GetRowCount(); if (rc == 0) { this.Mode = "UpdateNew"; this.UndoOperation = "Delete"; return(0); } if (rc > 1) { return(-1); } this.UndoOperation = "Update"; int colIndex = 0; DatabaseRow row = rs.GetRow(0); foreach (string col in allColumns) { string v = row.GetColumn(colIndex++); if (v != null) { UPCRMUndoField undoField = this.FieldDictionary[col]; undoField.OldValue = v; } } return(0); }
/// <summary> /// Loads from database. /// </summary> /// <param name="database">The database.</param> /// <returns>True if success, else false</returns> public virtual bool LoadFromDatabase(IDatabase database) { DatabaseRecordSet recordSet = new DatabaseRecordSet(database); string sql = @"SELECT json, error, errorcode, response, titleLine, detailsLine, imageName, serverRequestNumber, servertime, sessionid, translationkey, relatedInfo, baseerror, appversion, errorstack FROM requests WHERE requestnr = ?"; recordSet.Query.Prepare(sql); recordSet.Query.Bind(1, this.RequestNr); int ret = recordSet.Execute(); if (ret == 0 && recordSet.GetRowCount() > 0) { this.Loaded = true; DatabaseRow row = recordSet.GetRow(0); this.Json = row.GetColumn(0); this.blockExecution = false; if (!row.IsNull(1)) { string cError = row.GetColumn(1); if (cError == Constants.OFFLINEREQUEST_BLOCKED_TEXT) { this.blockExecution = true; } this.Error = row.GetColumn(1); } this.Code = row.GetColumnInt(2, -1); if (!row.IsNull(3)) { this.Response = row.GetColumn(3); } if (!row.IsNull(4)) { this.titleLine = row.GetColumn(4); } if (!row.IsNull(5)) { this.detailsLine = row.GetColumn(5); } if (!row.IsNull(6)) { this.imageName = row.GetColumn(6); } if (!row.IsNull(7)) { this.ServerRequestNumber = row.GetColumnInt(7); } if (!row.IsNull(8)) { this.ServerDateTime = row.GetColumn(8); } if (!row.IsNull(9)) { this.ServerSessionId = row.GetColumn(9); } if (!row.IsNull(10)) { this.ErrorTranslationKey = row.GetColumn(10); } if (!row.IsNull(11)) { string _relatedInfo = row.GetColumn(11); this.RelatedInfoDictionary = _relatedInfo.JsonDictionaryFromString(); } if (!row.IsNull(12)) { this.BaseErrorCode = row.GetColumnInt(12); } if (!row.IsNull(13)) { this.ApplicationVersion = row.GetColumn(13); } if (!row.IsNull(14)) { this.ErrorStack = row.GetColumn(14); } return(true); } return(false); }