Page 1 of 4 123 ... LastLast
Results 1 to 10 of 35

Thread: Alternative for ODBC Database

  1. #1
    Member
    Join Date
    Mar 2009
    Location
    Netherlands
    Age
    52
    Posts
    248
    Rep Power
    40

    Alternative for ODBC Database

    My script does crash sometimes and sometimes not, and always on different points (although it's doing the same thing everytime). Couldn't find something wrong in my code so after days of debugging my script I discovered that included ODBC code must be the cause.

    Maybe I wrote wrong ODBC code or maybe there's something wrong with ThinBasic's handling of ODBC. However I don't want to use ODBC anymore. Also because my knowledge about ODBC is limited so I don't know how I can build the things that I want (for example an 'find next' function).

    So I am wondering if there is a good alternative to setup a database in ThinBasic? Anybody knows....?

    Thanks in advance,

    Martin

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: Alternative for ODBC Database

    Hi Martin,

    in which way are you used to access databases other than ODBC way, do you have some previous experience from MS Access VBA coding? What kind approach would you like to see?


    Petr

    EDIT: could you please show the problematic part of code?
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3
    Member
    Join Date
    Mar 2009
    Location
    Netherlands
    Age
    52
    Posts
    248
    Rep Power
    40

    Re: Alternative for ODBC Database

    Hi Peter!

    If I remember well, I used ADO in Visual Basic, that was really easy method and I never had any problems.

    What do you think about setting up a database with a binary file in Thinbasic (by using FILE module), I guess that's pretty fast too?

    B.t.w. I am at work now, but when I'm home I will post my part of (wrong?) ODBC code from which I believe that it seems to make ThinBasic unpredictable.

    Greetings,

    Martin

  4. #4
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    159

    Re: Alternative for ODBC Database

    Look at FILE_GETR in the help file, I think its what your looking for or just write your own database.
    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

  5. #5
    Member
    Join Date
    Mar 2009
    Location
    Netherlands
    Age
    52
    Posts
    248
    Rep Power
    40

    Re: Alternative for ODBC Database

    Here's the code that seems to be wrong:

           OdbcFreeStmt hStmt,0    
           OdbcExecDirect hStmt, "SELECT TOP 1 * FROM music WHERE filename LIKE '%" & texttosql(file_pathsplit(bestand,%Path_RootPathProg)) & "%' AND extension LIKE '%" & texttosql(file_pathsplit(bestand,%Path_ext)) & "%'"       
           odbcsetabsoluteposition hstmt,1
                                 
           szArtist = texttosql(ListView_GetItemText(tabdatabase, %listview1,irec,2)) :cbArtist = LEN(szArtist)
           szTitle = texttosql(ListView_GetItemText(tabdatabase, %listview1,irec,3)):cbTitle = LEN(szTitle)    
           szDuration = texttosql(ListView_GetItemText(tabdatabase, %listview1,irec,4)):cbDuration = LEN(szDuration)  
           szGenres = texttosql(ListView_GetItemText(tabdatabase, %listview1,irec,5)):cbGenres = LEN(szGenres)  
           szYear = texttosql(ListView_GetItemText(tabdatabase, %listview1,irec,6)):cbYear = LEN(szYear)  
           szRating = texttosql(ListView_GetItemText(tabdatabase, %listview1,irec,7)):cbRating = LEN(szRating)  
           szTempo = texttosql(ListView_GetItemText(tabdatabase, %listview1,irec,8)):cbTempo = LEN(szTempo)  
           szBitrate = texttosql(Bitrate):cbBitrate = LEN(szBitrate)  
           szRelease = texttosql(release):cbRelease = LEN(szRelease)    
           szLastPlayed = "0":cbLastPlayed = LEN(szLastPlayed)     
           szTimesPlayed = "0":cbTimesPlayed = LEN(szTimesPlayed)  
           szInstrDub = instrdub:cbInstrDub = LEN(szInstrDub)
           szAcappella = acappella:cbAcappella = LEN(szAcappella)
           szMegamix = megamix:cbMegamix = LEN(szMegamix) 
           szRemix = remix:cbRemix = LEN(szRemix)  
           szChristmas = christmas:cbChristmas = LEN(szChristmas)
           szAnalyzed = "y":cbAnalyzed = LEN(szAnalyzed)    
     
           OdbcUpdateRecord hStmt
           OdbcFreeStmt hStmt,0  
           OdbcExecDirect hStmt, "SELECT * FROM music ORDER BY SID"  
    
    function texttosql(txt as string) as string 'replace forbidden characters in sql string
      txt=replace$(txt,"'",$dq)
      txt=replace$(txt,"\","|")     
      txt=replace$(txt,"[","<")
      txt=replace$(txt,"]",">")  
      function=txt
    end function
    
    function sqltotext(txt as string) as string 
      txt=replace$(txt,$dq,"'")
      txt=replace$(txt,"|","\")  
      txt=replace$(txt,"<","[")            
      txt=replace$(txt,">","]")              
      function=txt
    end function
    
    ThinBasic always seems to crash somewhere else as soon this code has been executed multiple times.
    If I remove this code the interpreter works fine.

  6. #6

    Re: Alternative for ODBC Database

    Can you post the code for the variable definitions?

  7. #7

    Re: Alternative for ODBC Database

    What is this $dg inside the functions?

  8. #8

    Re: Alternative for ODBC Database

    Ok, I see, double quote.

  9. #9
    Member
    Join Date
    Mar 2009
    Location
    Netherlands
    Age
    52
    Posts
    248
    Rep Power
    40

    Re: Alternative for ODBC Database

    Quote Originally Posted by Michael Hartlef
    Can you post the code for the variable definitions?
    Sure, I added them to my previous post.

    And here are the (global) variable definitions:

    dim hStmt as dword
    dim szFilename   AS ASCIIZ * 256
    dim szExtension  AS ASCIIZ * 11 
    dim szArtist    AS ASCIIZ * 151
    dim szTitle    AS ASCIIZ * 151 
    dim szDuration   AS ASCIIZ * 9 
    dim szGenres    AS ASCIIZ * 51
    dim szYear     AS ASCIIZ * 5
    dim szRating    AS ASCIIZ * 6 
    dim szTempo    AS ASCIIZ * 7
    dim szBitrate   AS ASCIIZ * 4 
    dim szRelease   AS ASCIIZ * 16
    dim szAdded    AS ASCIIZ * 11  
    dim szLastPlayed  AS ASCIIZ * 11
    dim szTimesPlayed AS ASCIIZ * 11  
    dim szInstrDub   AS ASCIIZ * 2 
    dim szAcappella  AS ASCIIZ * 2  
    dim szMegamix   AS ASCIIZ * 2 
    dim szRemix    AS ASCIIZ * 2  
    dim szChristmas  AS ASCIIZ * 2 
    dim szAnalyzed   AS ASCIIZ * 2
    

  10. #10

    Re: Alternative for ODBC Database

    Hi Martin,

    so far it looks good. But I would change some things to track the error down more.

    1) try DIM hStmt as LONG. We had a weird problem with image handles before and even we thought that DWORD was the correct variable type, we got sometimes no result. Sometimes we did. But with LONG it work all the time.

    2) Then seprate your code lines, don't use ":" to split them. You never know if the parser get's confused. The thinbasic parser isn't 100% bullet proofed.

    3) If you can, comment your ODBC lines out to see if the LISTVIEW commands work fine.

    4) If all this doesn't help, then I think the problem is that you use a much lower version of ODBC then the ODBC driver that thinBAsic uses.

Page 1 of 4 123 ... LastLast

Similar Threads

  1. how to create a simple ODBC database?
    By martin in forum ODBC
    Replies: 19
    Last Post: 13-08-2010, 14:24

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

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