Attached (and here below) an example trying to insert more data than the field can have, field ShortText20Chars
Example generates the following ADODB error:--> Error happened:
Error type: OLE DB provider error
Error number: -2147217887 [&H80040E21]
Description: Multiple-step operation generated errors. Check each status value.
Source: Microsoft Cursor Engine
I think we are in scenario 1 of the scenarios exposed here: http://www.adopenstatic.com/faq/80040e21.asp
I will go into this direction:
- I will implement RecordSet.Fields ... interface in order to be able to inspect fields characteristics. This can also be used to verify field existence
- I will add an optional parameter into RecordSet.UpdateS in order to be able to specify if to check field max data length and truncate input string value
Stay tuned.
Ciao
Eros
Uses "Console"Uses "ADODB"
Dim pConnection As New ADODB_CONNECTION
Dim sConn As String
Dim sSql As String
'----------------------------------
Function Add_New_Record(pConn As ADODB_CONNECTION, sShort20 As string, sShort200 As string, sLong As string)
'----------------------------------
Dim pRS As New ADODB_RECORDSET
pRs.CursorLocation = %ADUSECLIENT
sSql = "select * from T_Test_Strings where ID = -1"
'---Wil not return any record because ID = 0
PrintL "Query:", ssql
pRs.OPEN sSql, pConn, %ADOPENDYNAMIC, %ADLOCKOPTIMISTIC, %ADCMDTEXT
If pRS.State = %ADSTATEOPEN Then
PrintL "Records found", pRs.RecordCount
If pRS.RecordCount = 1 Then
PrintL "Update (Should not happen in this example)" In %CCOLOR_FYELLOW
End If
If pRS.RecordCount = 0 Then
PrintL "Insert record" In %CCOLOR_FYELLOW
pRs.addnew
pRs.UpdateS("ShortText20Chars") = repeat$(200, sShort20) '---THIS WILL GENERATE ERROR because field is only 20 bytes
pRs.UpdateS("ShortText200Chars") = sShort200 & " " & Timer '---This field is 200 bytes
pRs.UpdateS("LongText") = sLong '---This field has dynamic size
pRs.update
'---To check if there is an error, always use connection and Errors.Count method
If pConn.Errors.Count Then
PrintL "--> Error happened:" In %CCOLOR_FLIGHTRED
printl pConn.Errors.Msg
'PrintL "Error number..:", pConn.Errors(1).Number
'PrintL "Description...:", pConn.Errors(1).Description
'PrintL "Source........:", pConn.Errors(1).Source
'PrintL "SQLState......:", pConn.Errors(1).SQLState
'PrintL "NativeError...:", pConn.Errors(1).NativeError
pConn.Errors.Clear
End If
End If
PrintL " pRecordSet.Close :", pRS.CLOSE
End If
End Function
'---------------------------------------------------------------
' Connection
'---------------------------------------------------------------
sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & APP_SourcePath & "biblio.mdb"
'sConn = "Provider=sqloledb;Data Source=\\server\db;Initial Catalog=KNI2M;User Id=xxxxxx;Password=yyyyy ;"
'---Set connection string
pConnection.ConnectionString = sConn
PrintL "-Connection------------------------------------------"
PrintL " Opening ..." , pConnection.OPEN'(sConn)
'PrintL " pConnection.Connectionstring:" , pConnection.Connectionstring
PrintL " pConnection.State :" , pConnection.State
PrintL " pConnection.Version :" , pConnection.Version
PrintL "-Press a key to continue------------------------------" In %CCOLOR_FYELLOW
'---To check if there is ana arror, always use connection and ErrorsCount method
If pConnection.Errors.Count Then
'---Show all errors in one go.
'---This function also clear internal errors collection
PrintL pConnection.Errors.Msg
End If
If pConnection.State = %ADSTATEOPEN Then
Add_New_Record(pConnection, "Short20", "Short200", Repeat$(100, "Long Text repeated") )
PrintL " pConnection.Close :", pConnection.CLOSE
Else
PrintL "-It was not possible to open a connection-" In %CCOLOR_FLIGHTRED
End If
PrintL
PrintL "-Press a key to finish-------------------------------"
WaitKey
Bookmarks