Announcement

Collapse
No announcement yet.

Can't Seem to Retrieve contents of BLOB

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • #21
    Originally posted by Stuart McLachlan View Post

    Not at all. You can have multiple databases open at the same time in a single threaded application. Whether/when to use threads and SQL_Thread is solely dependent on what you are doing with the data and issues such as application responsiveness
    Yeah, I asked that badly. In a previous post, I read that the program had 2 connections with four statements each, but setting %THREADMAX=6. I meant to clarify if the OP was using one thread per statement rather than one thread per connection. I understand that multiple connections can be made in the same thread (I do it very often).
    Real programmers use a magnetized needle and a steady hand

    Comment


    • #22
      Yes. FYI, I am using only verbose statements because I have 2 databases I'm working with, and I have 7 statement levels to handle threads. My plan was to keep one persistent connection (in the main thread) and then open and close the other connections as needed. But I'm not sure that's the best plan. In my threads I am using SQL_OpenDataBase(2), but my main thread also uses database 2. So I wasn't sure I should use SQL_CloseDatabase(2) in a thread.
      Craig J. Slane
      Nostalga Sim Baseball

      Comment


      • #23
        Just wanted to say thanks to all for helping me on this learning curve with threads. I've got things in good shape now. FYI, when you open a new database connection inside the wrapper thread, it should be done with SQL functions directly in the wrapper and not by an external call to the main thread. I finally figured this out the hard way by trial and error. I also used the non-verbose functions to open and close the database inside this thread, otherwise there were problems because the same database needed to be accessible from my main thread. So here is my wrapper code that seems to work without a hitch (I created a MySQL user named 'livechat' with the appropriate permissions):

        '=====================BEGIN LIVE CHAT===========================================
        '===============================================================================
        THREAD FUNCTION livechatWrapper(BYVAL x&) AS LONG
        Local lResult&,sqlResult&,dsnF as Long
        SQL_THREAD %THREAD_START,6

        start_up:
        chatCloseFlag& = 0
        dsnF = FreeFile
        Open EZ_AppPath+"sql-3.dsn" For output As #dsnF
        Print #dsnF,"[ODBC]"
        Print #dsnF,"DRIVER=MySQL ODBC 5.3 Unicode Driver"
        Print #dsnF,"UID=livechat"
        Print #dsnF,"PWD=xxxxx"
        Print #dsnF,"PORT=xxxxx"
        Print #dsnF,"DATABASE="xxxxxx"
        Print #dsnF,"SERVER="xxxxxx"
        Close #dsnF

        sqlResult& = SQL_OpenDB(EZ_AppPath+"sql-3.dsn",%PROMPT_TYPE_NOPROMPT)
        If sqlResult& = %SQL_SUCCESS Or sqlResult& = %SUCCESS_WITH_INFO Then
        Try
        Kill EZ_AppPath+"sql-3.dsn"
        Catch
        End Try
        Do
        If SQL_DBisOpen = -1 Then
        EZ_SetColor "Form19",%Form19_Shape1,0,18 'green
        liveChat(1)
        EZ_SetColor "Form19",%Form19_Shape1,0,41 'gray
        For x& = 1 to 30
        If chatCloseFlag& = 1 Then finish_up
        Sleep 1000
        Next x&
        Else
        Goto start_up
        End If
        Loop Until chatCloseFlag& = 1
        Goto finish_up
        Else
        errorAudit "Couldn't Open Chat Thread"
        End If

        finish_up:
        If SQL_DBisOpen = -1 Then SQL_CloseDB
        SQL_THREAD %THREAD_STOP,6
        END FUNCTION
        Last edited by Craig Slane; 7 Jul 2018, 07:16 PM. Reason: Removed table name and server name
        Craig J. Slane
        Nostalga Sim Baseball

        Comment


        • #24
          Jumping out of (nested) loops using GOTO's? Ouch :

          Code:
          start_up:
          ...
          Do
             If SQL_DBisOpen = -1 Then
                For x& = 1 to 30
                      If chatCloseFlag& = 1 Then finish_up
          ...
                Next x&
             Else
          Goto start_up
             End If
          Loop Until chatCloseFlag& = 1
          ...
          finish_up:
          ...
          You may like to look at the Help entry for "EXIT"


          Comment


          • #25
            Stuart, the code I posted is a thread. If I shutdown a thread that way I have no more connection in my main thread right? Now, that raises a question: should I always be opening and closing my main thread connection just like a thread? Or, is it okay to try and keep a persistent connection in the main thread? I ask because I do note that SQL_Thread still throws the error %ERROR_CANNOT_BE_DONE from time to time. Thoughts?
            Craig J. Slane
            Nostalga Sim Baseball

            Comment


            • #26
              How does EXIT from a DO/LOOP affect (directly) the containing tread any more than GOTO outside the LOOP (which is not recommended methed)?

              In any case, here is your post 23 code re-indented, and with LABELs replaced by an outer DO/LOOP, and GOTOs replaced with EXIT, ITERATE and EXIT.
              Code:
              '=====================BEGIN LIVE CHAT===========================================
              '===============================================================================
              thread function livechatWrapper(byval x&) as long
                local lResult&,sqlResult&,dsnF as long
                SQL_THREAD %THREAD_START,6
              
                do 'start_up:
                  chatCloseFlag& = 0                                 '<<--- a change
                  dsnF = freefile
                  open EZ_AppPath+"sql-3.dsn" for output as #dsnF
                  print #dsnF,"[ODBC]"
                  print #dsnF,"DRIVER=MySQL ODBC 5.3 Unicode Driver"
                  print #dsnF,"UID=livechat"
                  print #dsnF,"PWD=xxxxx"
                  print #dsnF,"PORT=xxxxx"
                  print #dsnF,"DATABASE="xxxxxx"
                  print #dsnF,"SERVER="xxxxxx"
                  close #dsnF
              
                  sqlResult& = SQL_OpenDB(EZ_AppPath+"sql-3.dsn",%PROMPT_TYPE_NOPROMPT)
                  if sqlResult& = %SQL_SUCCESS or sqlResult& = %SUCCESS_WITH_INFO then
                    try
                      kill EZ_AppPath+"sql-3.dsn"
                    catch
                    end try
                    do
                      if SQL_DBisOpen = -1 then
                        EZ_SetColor "Form19",%Form19_Shape1,0,18 'green
                        liveChat(1)
                        EZ_SetColor "Form19",%Form19_Shape1,0,41 'gray
                        for x& = 1 to 30
                          if chatCloseFlag& = 1 then finish_up
                          sleep 1000
                        next x&
                      else
                        exit, exit, iterate 'Goto start_up       '<<--- a change and edit at 09:16 EDT
                      end if
                    loop until chatCloseFlag& = 1
                    exit loop 'Goto finish_up
                  else                                               '<<--- a change
                    errorAudit "Couldn't Open Chat Thread"
                  end if
              
                loop 'finish_up:                                     '<<--- a change
                if SQL_DBisOpen = -1 then SQL_CloseDB
                SQL_THREAD %THREAD_STOP,6
              end function
              I make no comment on correctness of the rest of the code. I made changes at 4 places to get rid of the GOTOs.

              Cheers,

              edit - EXIT LOOP comma ITERATE LOOP gave compile error. another EXIT added because IF is the "nearest" block, then original DO block, then added outer DO block.
              Dale

              Comment

              Working...
              X