Page 4 of 4 FirstFirst ... 234
Results 31 to 35 of 35

Thread: ADODB Question

Share/Bookmark
  1. #31
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    50
    Posts
    8,091
    Blog Entries
    2
    Rep Power
    10
    Ciao Axel,

    thanks a lot for your reporting, always a pleasure to get such a feedback.
    To know other people are using your software for real problems and seems having good results ... is a great push for doing better.

    I will check what happen when field name is not valid.
    I was working on ADODB Fields collection ( https://docs.microsoft.com/en-us/sql...lds-collection ) for the next version.
    Maybe it will help on this.

    Will let you know.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  2. #32
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    50
    Posts
    8,091
    Blog Entries
    2
    Rep Power
    10
    Quote Originally Posted by axelmoe View Post
    -if eg. the target field in pRS.update is a string with 20 digits and I set a value with 15 digits I get no error and teh field value is not set
    When you say "digits" you mean "characters"?
    So you are saying that you always have to fill the string with the exact number of characters of the target Table field?
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  3. #33
    yes I mean characters.
    e.g.
    The target field is defined by 20 characters, not mandatory. When I set Zero to 20 characters all was fine.
    When I set more then 20 characters the field the target field in the DB is not updated

    Axel

  4. #34
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    50
    Posts
    8,091
    Blog Entries
    2
    Rep Power
    10
    OK, now I got it.

    Inserting more bytes than the one allowed by a field, generates an error. I do not know if it is possible to switch into a warning.
    Internally I can automatically fix it truncating data to the max allowed by the field but is an assumption I cannot keep for all situations. There are situations where this is not valid and depends by the programmer.
    I will check what I can do, maybe adding few personalized options (not ADODB standard) to activate/deactivate.
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  5. #35
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    50
    Posts
    8,091
    Blog Entries
    2
    Rep Power
    10
    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
    
    Attached Files Attached Files
    Last edited by ErosOlmi; 24-04-2017 at 12:48.
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

Page 4 of 4 FirstFirst ... 234

Similar Threads

  1. Question of the day ;)
    By Petr Schreiber in forum thinBasic General
    Replies: 8
    Last Post: 23-08-2010, 19:58
  2. C to TB question
    By Michael Clease in forum Other languages
    Replies: 2
    Last Post: 03-06-2010, 12:11
  3. gdi question
    By Lionheart008 in forum UI (User Interface)
    Replies: 6
    Last Post: 07-12-2009, 19:31
  4. UDT question
    By sandyrepope in forum thinBasic General
    Replies: 3
    Last Post: 18-02-2008, 22:33
  5. m15 question
    By kryton9 in forum M15 file format
    Replies: 4
    Last Post: 20-06-2007, 20:18

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •