Recent Posts

Pages: 1 ... 5 6 [7] 8 9 10
61
ScriptBasic Blog / Re: ScriptBasic 3.0
« Last post by John on April 14, 2024, 06:21:32 PM »
I figured out what the issue was with OxygenBasic calling functions with a 64 bit pointer. I replaced cdecl with ms64 and the program compiled and ran. There still is an issue passing a double (real) to O2.

Code: Text
  1. ' O2 SB Embed
  2.  
  3. % filename "o2sb64.exe"
  4. includepath "$/inc/"
  5. uses rtl64
  6.  
  7. % libScriba = "libScriba.dll"
  8. indexbase 0
  9.  
  10. type SbData
  11.   typ as dword
  12.   siz as dword
  13.   union {
  14.     dbl as double
  15.     lng as sys
  16.     str as char*
  17.     gen as sys
  18.   }
  19. end type
  20.  
  21. #define SBT_UNDEF  0
  22. #define SBT_DOUBLE 1
  23. #define SBT_LONG   2
  24. #define SBT_STRING 3
  25. #define SBT_ZCHAR  4
  26.  
  27. sys pProgram, iError, cArgs
  28. sys f1, f2, v
  29. sys n, m
  30. sys qdat
  31. SbData ReturnData, ArgData[3]
  32. sbData pdat
  33.  
  34. sys sb=LoadLibrary libScriba
  35.  
  36. extern ms64
  37.   bind sb
  38.   {
  39.   scriba_new
  40.   scriba_SetStdin()
  41.   scriba_SetStdout()
  42.   scriba_SetEmbedPointer()
  43.   scriba_LoadConfiguration
  44.   scriba_destroy
  45.   scriba_DestroySbData
  46.   scriba_SetFileName
  47.   scriba_LoadSourceProgram
  48.   scriba_LoadProgramString
  49.   scriba_Run
  50.   scriba_GetVariable
  51.   scriba_SetVariable
  52.   scriba_LookupVariableByName
  53.   scriba_LookupFunctionByName
  54.   scriba_Call
  55.   scriba_CallArg
  56.   scriba_NewSbArgs
  57.   scriba_CallArgEx
  58.   scriba_DestroySbArgs
  59.   scriba_DestroySbData
  60.   scriba_NewSbString
  61.   }
  62. end extern
  63.  
  64. function newmem ms64 (sys le) as sys, export
  65.   return getmemory le
  66. end function
  67.  
  68. function freemem ms64 (sys p) export
  69.   freememory p
  70. end function
  71.  
  72. pProgram = scriba_new(@newmem, @freemem)
  73. scriba_LoadConfiguration(pProgram, "C:\Windows\SCRIBA.INI")
  74. scriba_SetFileName(pProgram, "test.sb")
  75. scriba_LoadSourceProgram(pProgram)
  76. scriba_Run(pProgram,"")
  77.  
  78. ' Get Global Var  
  79. sbdata *p  
  80. v = scriba_LookupVariableByName(pProgram, "main::a")
  81. scriba_GetVariable(pProgram, v, @@p)
  82. print "A: " + str(p.lng)
  83.  
  84. ' Create SB Variant Array
  85. sbData *arg
  86. @arg = scriba_NewSbArgs(pProgram,"i r s", 1, .2, "three")
  87. print str(arg[0].lng) + " | " + str(arg[1].dbl) + " | " + arg[2].str
  88.  
  89. scriba_DestroySbArgs(pProgram, arg, 3)
  90. scriba_DestroySbData(pProgram, arg)  
  91. scriba_destroy(pProgram)
  92.  

test.sb
Code: ScriptBasic
  1. a = 99






Code: Text
  1. type SbData
  2.   typ as dword
  3.   siz as dword
  4.   union {
  5.     dbl as double
  6.     lng as sys
  7.     str as char*
  8.     gen as sys
  9.   }
  10. end type
  11.  

I tried all the other O2 floating point types besides double and nothing works.  :-[
62
ScriptBasic Blog / Re: ScriptBasic 3.0
« Last post by John on April 14, 2024, 02:29:48 PM »
I've added the ODBC FetchSchema() function to the sb-dev-msvc repository branch. I've pushed the code to the repo.

Linux
Code: ScriptBasic
  1. IMPORT odbc.bas
  2.  
  3. dbh = odbc::RealConnect("PSQL","postgres","<Password>")
  4. SQL = "SELECT * FROM film LIMIT 1"
  5. odbc::Query(dbh, SQL)    
  6. odbc::FetchSchema(dbh, col)
  7. odbc::Close(dbh)
  8.  
  9. FOR x = 0 TO UBOUND(col) STEP 5
  10.   PRINT FORMAT("Column Name: %s, Type: %i, Size: %i, Digits: %i, Nullable: %i\n", col[x], col[x + 1], col[x + 2], col[x + 3], col[x + 4])
  11. NEXT
  12.  


jrs@linux-dev:~/sb/examples$ scriba getschema.sb
Column Name: film_id, Type: 4, Size: 10, Digits: 0, Nullable: 0
Column Name: title, Type: 12, Size: 255, Digits: 0, Nullable: 0
Column Name: description, Type: -1, Size: 8190, Digits: 0, Nullable: 1
Column Name: release_year, Type: 4, Size: 10, Digits: 0, Nullable: 1
Column Name: language_id, Type: 5, Size: 5, Digits: 0, Nullable: 0
Column Name: rental_duration, Type: 5, Size: 5, Digits: 0, Nullable: 0
Column Name: rental_rate, Type: 2, Size: 4, Digits: 2, Nullable: 0
Column Name: length, Type: 5, Size: 5, Digits: 0, Nullable: 1
Column Name: replacement_cost, Type: 2, Size: 5, Digits: 2, Nullable: 0
Column Name: rating, Type: 12, Size: 255, Digits: 0, Nullable: 1
Column Name: last_update, Type: 93, Size: 26, Digits: 6, Nullable: 0
Column Name: special_features, Type: 12, Size: 255, Digits: 0, Nullable: 1
Column Name: fulltext, Type: 12, Size: 255, Digits: 0, Nullable: 0
jrs@linux-dev:~/sb/examples$


Windows 64 Bit
Code: ScriptBasic
  1. IMPORT odbc.bas
  2.  
  3. dbh = ODBC::RealConnect("SB64","","")
  4.  
  5. ODBC::query(dbh, "SELECT TOP 1 * FROM TaskEntry")
  6.  
  7. odbc::FetchSchema(dbh, col)
  8. odbc::Close(dbh)
  9.  
  10. FOR x = 0 TO UBOUND(col) STEP 5
  11.   PRINT FORMAT("Column Name: %s, Type: %i, Size: %i, Digits: %i, Nullable: %i\n", col[x], col[x + 1], col[x + 2], col[x + 3], col[x + 4])
  12. NEXT
  13.  


C:\ScriptBasic64\examples>scriba fetchschema.sb
Column Name: GridSort, Type: -9, Size: 40, Digits: 0, Nullable: 0
Column Name: ClientCode, Type: -9, Size: 25, Digits: 0, Nullable: 0
Column Name: TaskCode, Type: -9, Size: 30, Digits: 0, Nullable: 0
Column Name: TaskDate, Type: -9, Size: 15, Digits: 0, Nullable: 0
Column Name: Billable, Type: 2, Size: 4, Digits: 2, Nullable: 1
Column Name: NonBillable, Type: 2, Size: 4, Digits: 2, Nullable: 1
Column Name: DiscoveryDemo, Type: 2, Size: 4, Digits: 2, Nullable: 1
Column Name: Bill, Type: -8, Size: 1, Digits: 0, Nullable: 0
Column Name: TaskNotes, Type: -10, Size: 1073741823, Digits: 0, Nullable: 0
Column Name: BillingComplete, Type: -8, Size: 1, Digits: 0, Nullable: 0

C:\ScriptBasic64\examples>


ODBC SQL Column Type Values

ODBC    JDBC    Data Type
-11    -11    GUID
 -7     -7    BIT
 -6     -6    TINYINT
 -5     -5    BIGINT
 -4     -4    LONGVARBINARY
 -3     -3    VARBINARY
 -2     -2    BINARY
 -1     -1    LONGVARCHAR
  0      0    Unknown type
  1      1    CHAR
  2      2    NUMERIC
  3      3    DECIMAL
  4      4    INTEGER
  5      5    SMALLINT
  6      6    FLOAT
  7      7    REAL
  8      8    DOUBLE
  9     91    DATE
 10     92    TIME
 11     93    TIMESTAMP
 12     12    VARCHAR

Unicode SQL types for ODBC applications working with multibyte character sets, such as in Chinese, Hebrew, Japanese, or Korean locales.

ODBC          Data Type
-10          WLONGVARCHAR
 -9          WVARCHAR


Remember to add the FetchSchema DECLARE to your odbc.bas include file. It's added if you build from source.
63
ScriptBasic Blog / Re: ScriptBasic 3.0
« Last post by John on April 13, 2024, 09:44:10 PM »
All the modules released on all platforms are now working. If you have time to give ScriptBasic a try and let me know if you find any issue that would be great. I need to get back to a project I'm working on so that's it from me for a while.
64
ScriptBasic Blog / Re: ScriptBasic 3.0
« Last post by John on April 13, 2024, 08:40:34 PM »
Everything works fine with the changes I made on the Linux side on Windows 64 bit MSVC. I pushed the change to the ScriptBasic repository.

Code: ScriptBasic
  1. IMPORT odbc.bas
  2.  
  3. dbh = ODBC::RealConnect("SB64","","")
  4.  
  5. ODBC::query(dbh, "SELECT * FROM TaskEntry")
  6.  
  7. WHILE ODBC::FetchHash(dbh,column)
  8.   PRINT column{"ClientCode"}," - ",column{"TaskCode"},"\n"
  9. WEND
  10.  
  11. ODBC::Close(dbh)
  12.  


C:\ScriptBasic64\examples>scriba sql_odbc.sb
3FCONST - SPI-100-SERVICE
AC PRO - SPI-100-SERVICE
AC PRO - SPI-100-NC
AC PRO - SPI-100-DIS/DEM
AC PRO - SPI-100-SERVICE
AC PRO - SPI-100-DIS/DEM
AC PRO - SPI-100-DIS/DEM
AC PRO - SPI-100-SERVICE
AC PRO - SPI-100-SERVICE
AC PRO - SPI-100-NC
BACKLAN - SPI-100-SERVICE
BACKLAN - SPI-100-DIS/DEM
BACKLAN - SPI-100-NC

C:\ScriptBasic64\examples>


65
ScriptBasic Blog / Re: ScriptBasic 3.0
« Last post by John on April 13, 2024, 07:53:43 PM »
I found the the issue with FetchHash(). I'm going to try these changes on the Windows 64 MSVC version to make sure it works there as well. If all is good, I'll push the changes to the repo.
Code: C
  1.   SQLULEN ColSize; // JRS
  2. // SQLUINTEGER ColSize;
  3.  

Code: ScriptBasic
  1. IMPORT odbc.bas
  2.  
  3. ON ERROR GOTO Ouch
  4. dbh = ODBC::RealConnect("PSQL","postgres","<Password>")
  5.  
  6. ODBC::Query(dbh, "SELECT * FROM film LIMIT 10")
  7.  
  8. WHILE ODBC::FetchHash(dbh,column)
  9.   PRINT column{"title"}," - ",column{"description"}, "\n"
  10. WEND
  11.  
  12. Done:
  13. ODBC::Close(dbh)
  14. END
  15.  
  16. Ouch:
  17. PRINT "DEBUG: ", ODBC::Error(dbh), "\n"
  18. GOTO Done
  19.  

Code: Text
  1. jrs@linux-dev:~/sb/examples$ scriba sql_odbc.sb
  2. Chamber Italian - A Fateful Reflection of a Moose And a Husband who must Overcome a Monkey in Nigeria
  3. Grosse Wonderful - A Epic Drama of a Cat And a Explorer who must Redeem a Moose in Australia
  4. Airport Pollock - A Epic Tale of a Moose And a Girl who must Confront a Monkey in Ancient India
  5. Bright Encounters - A Fateful Yarn of a Lumberjack And a Feminist who must Conquer a Student in A Jet Boat
  6. Academy Dinosaur - A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies
  7. Ace Goldfinger - A Astounding Epistle of a Database Administrator And a Explorer who must Find a Car in Ancient China
  8. Adaptation Holes - A Astounding Reflection of a Lumberjack And a Car who must Sink a Lumberjack in A Baloon Factory
  9. Affair Prejudice - A Fanciful Documentary of a Frisbee And a Lumberjack who must Chase a Monkey in A Shark Tank
  10. African Egg - A Fast-Paced Documentary of a Pastry Chef And a Dentist who must Pursue a Forensic Psychologist in The Gulf of Mexico
  11. Agent Truman - A Intrepid Panorama of a Robot And a Boy who must Escape a Sumo Wrestler in Ancient China
  12. jrs@linux-dev:~/sb/examples$
  13.  
66
ScriptBasic Blog / Re: ScriptBasic 3.0
« Last post by John on April 13, 2024, 06:41:15 PM »
I have made some progress with the ODBC extension module on Linux. This 64-bit ODBC driver support guide was helpful to find the issue.

Code: C
  1.   SQLLEN cbCol,cbrCol; //JRS
  2.   // SQLINTEGER cbCol,cbrCol;
  3.  

This allowed me to get FetchArray to work. FethchHash still isn't working and I believe it might be a type issue as well.

Code: ScriptBasic
  1. IMPORT odbc.bas
  2.  
  3. ON ERROR GOTO Ouch
  4. dbh = ODBC::RealConnect("PSQL","postgres","<Password>")
  5.  
  6. ODBC::Query(dbh, "SELECT * FROM film LIMIT 25")
  7.  
  8. WHILE ODBC::FetchArray(dbh,column)
  9.   ' PRINT column{"title"}," - ",column{"description"}, "\n"
  10.  PRINT column[0],"\t",column[1],"\t",column[2],"\n"
  11. WEND
  12.  
  13. Done:
  14. ODBC::Close(dbh)
  15. END
  16.  
  17. Ouch:
  18. PRINT "DEBUG: ", ODBC::Error(dbh), "\n"
  19. GOTO Done
  20.  

Code: Text
  1. jrs@linux-dev:~/sb/examples$ scriba sql_odbc.sb
  2. 133     Chamber Italian A Fateful Reflection of a Moose And a Husband who must Overcome a Monkey in Nigeria
  3. 384     Grosse Wonderful        A Epic Drama of a Cat And a Explorer who must Redeem a Moose in Australia
  4. 8       Airport Pollock A Epic Tale of a Moose And a Girl who must Confront a Monkey in Ancient India
  5. 98      Bright Encounters       A Fateful Yarn of a Lumberjack And a Feminist who must Conquer a Student in A Jet Boat
  6. 1       Academy Dinosaur        A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies
  7. 2       Ace Goldfinger  A Astounding Epistle of a Database Administrator And a Explorer who must Find a Car in Ancient China
  8. 3       Adaptation Holes        A Astounding Reflection of a Lumberjack And a Car who must Sink a Lumberjack in A Baloon Factory
  9. 4       Affair Prejudice        A Fanciful Documentary of a Frisbee And a Lumberjack who must Chase a Monkey in A Shark Tank
  10. 5       African Egg     A Fast-Paced Documentary of a Pastry Chef And a Dentist who must Pursue a Forensic Psychologist in The Gulf of Mexico
  11. 6       Agent Truman    A Intrepid Panorama of a Robot And a Boy who must Escape a Sumo Wrestler in Ancient China
  12. 7       Airplane Sierra A Touching Saga of a Hunter And a Butler who must Discover a Butler in A Jet Boat
  13. 9       Alabama Devil   A Thoughtful Panorama of a Database Administrator And a Mad Scientist who must Outgun a Mad Scientist in A Jet Boat
  14. 10      Aladdin Calendar        A Action-Packed Tale of a Man And a Lumberjack who must Reach a Feminist in Ancient China
  15. 11      Alamo Videotape A Boring Epistle of a Butler And a Cat who must Fight a Pastry Chef in A MySQL Convention
  16. 12      Alaska Phantom  A Fanciful Saga of a Hunter And a Pastry Chef who must Vanquish a Boy in Australia
  17. 213     Date Speed      A Touching Saga of a Composer And a Moose who must Discover a Dentist in A MySQL Convention
  18. 13      Ali Forever     A Action-Packed Drama of a Dentist And a Crocodile who must Battle a Feminist in The Canadian Rockies
  19. 14      Alice Fantasia  A Emotional Drama of a A Shark And a Database Administrator who must Vanquish a Pioneer in Soviet Georgia
  20. 15      Alien Center    A Brilliant Drama of a Cat And a Mad Scientist who must Battle a Feminist in A MySQL Convention
  21. 16      Alley Evolution A Fast-Paced Drama of a Robot And a Composer who must Battle a Astronaut in New Orleans
  22. 17      Alone Trip      A Fast-Paced Character Study of a Composer And a Dog who must Outgun a Boat in An Abandoned Fun House
  23. 18      Alter Victory   A Thoughtful Drama of a Composer And a Feminist who must Meet a Secret Agent in The Canadian Rockies
  24. 19      Amadeus Holy    A Emotional Display of a Pioneer And a Technical Writer who must Battle a Man in A Baloon
  25. 20      Amelie Hellfighters     A Boring Drama of a Woman And a Squirrel who must Conquer a Student in A Baloon
  26. 21      American Circus A Insightful Drama of a Girl And a Astronaut who must Face a Database Administrator in A Shark Tank
  27. jrs@linux-dev:~/sb/examples$
  28.  
67
ScriptBasic Blog / Re: ScriptBasic 3.0
« Last post by John on April 12, 2024, 05:48:47 PM »
The new version of MSVC SBT works on Linux as well.

You may have noticed the main::<function / var name> reference. If you were using modules (name spaces) then you can use the name of your module instead of main (default name space) All names must be in lower case.

sbt_demo.sb
Code: ScriptBasic
  1. ' SBT 64 bit Linux Demo
  2.  
  3. IMPORT sbt.bas
  4.  
  5. sb_code = """
  6. FUNCTION prtvars(a, b, c)
  7.  PRINT a,"\\n"
  8.  PRINT FORMAT("%g\\n", b)
  9.  PRINT c,"\\n"
  10.  prtvars = "Function Return"
  11. END FUNCTION
  12.  
  13. a = 0
  14. b = 0
  15. c = ""
  16. """
  17.  
  18. sb = sbt::SB_New()
  19. sbt::SB_Configure sb, "/etc/scriba/basic.conf"
  20. sbt::SB_Loadstr sb, sb_code
  21. sbt::SB_NoRun sb
  22. ' Call function before running script
  23. funcrtn = sbt::SB_CallSubArgs(sb,"main::prtvars", 123, 1.23, "One, Two, Three")
  24. PRINT funcrtn,"\n"
  25. ' Run script initializing globals
  26. sbt::SB_Run sb, ""
  27. ' Assign variables values
  28. sbt::SB_SetInt sb, "main::a", 321
  29. sbt::SB_SetDbl sb, "main::b", 32.1
  30. sbt::SB_SetStr sb, "main::c", "Three,Two,One" & CHR(0)
  31. ' Call function again with variables assigned in the previous step
  32. sbt::SB_CallSubArgs sb, "main::prtvars", _
  33.           sbt::SB_GetVar(sb, "main::a"), _
  34.           sbt::SB_GetVar(sb, "main::b"), _
  35.           sbt::SB_GetVar(sb, "main::c")
  36. sbt::SB_Destroy sb
  37.  

Output

jrs@linux-dev:~/sb/examples$ scriba sbt_demo.sb
123
1.23
One, Two, Three
Function Return
321
32.1
Three,Two,One
jrs@linux-dev:~/sb/examples$


68
ScriptBasic Blog / Re: ScriptBasic 3.0
« Last post by John on April 12, 2024, 04:48:37 PM »
I got the threaded version of SBT API calling working. It also works with the MT module which I use as thread status flags. This way you don't have to make continuous calls to the thread to get its status.

sbt_start.sb
Code: ScriptBasic
  1. IMPORT mt.bas
  2. IMPORT sbt.bas
  3.  
  4. sb = SBT::SB_ThreadStart("sbt_base.sb", "","C:/Windows/SCRIBA.INI")
  5. ' Assign variables values
  6. rtn = SBT::SB_SetInt(sb, "main::a", 123)
  7. SBT::SB_SetDbl(sb, "main::b", 12.3)
  8. SBT::SB_SetStr(sb, "main::c", "One,Two,Three" & CHR(0))
  9. ' Call function with variables assigned in the previous step
  10. SBT::SB_CallSubArgs(sb, "main::prtvars", _
  11.           SBT::SB_GetVar(sb, "main::a"), _
  12.           SBT::SB_GetVar(sb, "main::b"), _
  13.           SBT::SB_GetVar(sb, "main::c"))
  14.  
  15. PRINT "Thread ",mt::GetVariable("thread_status"),"\n"
  16.  
  17. ' Terminate Thread
  18. SBT::SB_CallSub(sb, "main::end_thread")
  19.  

sbt_base.sb
Code: ScriptBasic
  1. IMPORT mt.bas
  2. IMPORT sbt.bas
  3.  
  4. FUNCTION prtvars(a, b, c)
  5.   PRINT a,"\n"
  6.   PRINT FORMAT("%g\n", b)
  7.   PRINT c,"\n"
  8.   prtvars = "Function Return"
  9. END FUNCTION
  10.  
  11. a = 0
  12. b = 0
  13. c = ""
  14.  
  15. mt::SetVariable("thread_status","Running")
  16.  
  17. SUB End_Thread
  18.   SBT::SB_ThreadEnd()
  19. END SUB
  20.  

Output

C:\ScriptBasic64\examples>scriba sbt_start.sb
123
12.3
One,Two,Three
Thread Running

C:\ScriptBasic64\examples>

69
ScriptBasic Blog / Re: ScriptBasic 3.0
« Last post by John on April 12, 2024, 03:10:41 PM »
I was able to get SBT working after my pointer based rewrite. I still have to test this on Linux before I push it to the repo.

Code: ScriptBasic
  1. ' SBT Demo
  2.  
  3. IMPORT sbt.bas
  4.  
  5. sb_code = """
  6. FUNCTION prtvars(a, b, c)
  7.  PRINT a,"\\n"
  8.  PRINT FORMAT("%g\\n", b)
  9.  PRINT c,"\\n"
  10.  prtvars = "Function Return"
  11. END FUNCTION
  12.  
  13. a = 0
  14. b = 0
  15. c = ""
  16. """
  17.  
  18. sb = SBT::SB_New()
  19. rtn = SBT::SB_Configure(sb, "C:/Windows/SCRIBA.INI")
  20. rtn = SBT::SB_Loadstr(sb, sb_code)
  21. rtn = SBT::SB_NoRun(sb)
  22. ' Call function before running script
  23. funcrtn = SBT::SB_CallSubArgs(sb,"main::prtvars", 123, 1.23, "One, Two, Three")
  24. PRINT funcrtn,"\n"
  25. ' Run script initializing globals
  26. rtn = SBT::SB_Run(sb, "")
  27. ' Assign variables values
  28. rtn = SBT::SB_SetInt(sb, "main::a", 321)
  29. rtn = SBT::SB_SetDbl(sb, "main::b", 32.1)
  30. rtn = SBT::SB_SetStr(sb, "main::c", "Three,Two,One" & CHR(0))
  31. ' Call function again with variables assigned in the previous step
  32. SBT::SB_CallSubArgs(sb, "main::prtvars", _
  33.           SBT::SB_GetVar(sb, "main::a"), _
  34.           SBT::SB_GetVar(sb, "main::b"), _
  35.           SBT::SB_GetVar(sb, "main::c"))
  36.  
  37. SBT::SB_Destroy(sb)
  38.  

Output


C:\ScriptBasic64\examples>scriba sbt_demo.sb
123
1.23
One, Two, Three
Function Return
321
32.1
Three,Two,One

C:\ScriptBasic64\examples>

70
ScriptBasic Blog / Re: ScriptBasic 3.0
« Last post by John on April 12, 2024, 10:09:12 AM »
I think I know what the problem is. I need to pass the sb object as a Pointer not an Integer (signed long). I got away with it on Windows 32 bit and Linux but Windows 64 bit has a greater memory range and is overflowing returning a negative value.

Pages: 1 ... 5 6 [7] 8 9 10