X-Sharp / XSharpPublic

Public repository for the source code for the XSharp Compiler, Runtime, Project System and Tools.
Apache License 2.0
89 stars 36 forks source link

System.Data.ReadOnlyException ReadOnly column #847

Open jpmoschi opened 2 years ago

jpmoschi commented 2 years ago

Good morning guys I still continued testing as long as you do not indicate otherwise. I can't append records in a Work Area created with sqlexec functiona. Dialect FoxPro

_hancle= SQLCONNECT("mysqlcon")
SQLEXEC(_handle,"SELECT '        ' CODESPE","sqlresult" )
? RecCount() // = 1 Ok
append blank // RecCount add 1 correctly 
? RecCount() // = 2 Ok
_FIELD->CODESPE:= "ASDF" // Error!!!: see error detail
// FieldPutSelect(Alias(),"CODESPE","ASDF") // the same error!!!

The error detail System.Data.ReadOnlyException: La columna 'CODESPE' es de solo lectura. en System.Data.DataRow.set_Item(DataColumn column, Object value) en XSharp.RDD.DBFVFPSQL.PutValue(Int32 nFldPos, Object oValue) en XSharp.CoreDb.<>c__DisplayClass49_0.b0() en XSharp.CoreDb.Do[T](Func`1 action) en XSharp.CoreDb.FieldPut(UInt32 nPos, Object xValue) en XSharp.RT.Functions.FieldSet(String fieldName, __Usual uValue) en NSOMA.Form2.ejemplo14() en C:\Users\jpmos\Source\repos\X-Sharp\WindowsFormsApplication1\Form2.prg:línea 1123

More detail (Exception class in Inmediate Window ) ? e {"La columna 'CODESPE' es de solo lectura."} Data: {System.Collections.ListDictionaryInternal} HResult: -2146232025 HelpLink: null IPForWatsonBuckets: 0x656cb479 InnerException: null IsTransient: FALSE Message: "La columna 'CODESPE' es de solo lectura." RemoteStackTrace: null Source: "System.Data" StackTrace: " at System.Data.DataRow.set_Item(DataColumn column, Object value) at XSharp.RDD.DBFVFPSQL.PutValue(Int32 nFldPos, Object oValue) at XSharp.CoreDb.<>c__DisplayClass49_0.b0() at XSharp.CoreDb.Do[T](Func`1 action) at XSharp.CoreDb.FieldPut(UInt32 nPos, Object xValue) at XSharp.RT.Functions.FieldSet(String fieldName, __Usual uValue) at NSOMA.Form2.ejemplo14() in C:\Users\jpmos\Source\repos\X-Sharp\WindowsFormsApplication1\Form2.prg:line 1123 at NSOMA.Form2.button1_Click(Object sender, EventArgs e) in C:\Users\jpmos\Source\repos\X-Sharp\WindowsFormsApplication1\Form2.prg:line 109 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at NSOMA.MyStartupCode.Start() in C:\Users\jpmos\Source\repos\X-Sharp\WindowsFormsApplication1\Program.prg:line 645" TargetSite: {Void set_Item(System.Data.DataColumn, System.Object)} WatsonBuckets: null _HResult: -2146232025 _className: "System.Data.ReadOnlyException" _data: {System.Collections.ListDictionaryInternal} _dynamicMethods: null _exceptionMethod: null _exceptionMethodString: null _helpURL: null _innerException: null _ipForWatsonBuckets: 0x656cb479 _message: "La columna 'CODESPE' es de solo lectura." _remoteStackIndex: 0 _remoteStackTraceString: null _safeSerializationManager: {System.Runtime.Serialization.SafeSerializationManager} _source: "System.Data" _stackTrace: {sbyte[768]} _stackTraceString: null _watsonBuckets: null _xcode: -532462766 _xptrs: 0x00000000

RobertvanderHulst commented 2 years ago

JP, In the example CODESPE is an alias for a column that has a literal value. Is this also the case in your real code, or is CODESPE a normal column or calculated column ?

jpmoschi commented 2 years ago

Robert, you can see the line SQLEXEC(_handle,"SELECT ' ' CODESPE","sqlresult" ) In MS Sql Server and some others Data Providers It is the same as SQLEXEC(_handle,"SELECT ' ' as CODESPE","sqlresult" )

CODESPE IS A DataColumn

jpmoschi commented 2 years ago

i re read you, it is nos part of a table, may be a calculated column.

RobertvanderHulst commented 2 years ago

Juan, I think the problem is that because it is a calculated column in the result set, the Ado.Net DataTable that we use to store the results for the cursor has marked the DataColumn it as readonly. I'll see if we can change that and make the column read/write.

jpmoschi commented 2 years ago

Yes, look the Object Browser exception of DataColumn ReadOnly property In Foxpro the Sqlexec Cursors Results are like disconnected DataTables. An equivalent to a Connected DataSet.DataTable in FoxPro is "Table Buffering"

public bool ReadOnly { get; set; } Member of System.Data.DataColumn

Summary: Gets or sets a value that indicates whether the column allows for changes as soon as a row has been added to the table.

Return Values: true if the column is read only; otherwise, false. The default is false.

Exceptions: System.ArgumentException: The property is set to false on a computed column.