r/qb64 • • Oct 10 '21

News QB64 v2.0 released! ⭐️⭐️⭐️⭐️⭐️

22 Upvotes

⭐️⭐️⭐️⭐️⭐️
Time to upgrade!
⭐️⭐️⭐️⭐️⭐️

QB64 v2.0 is now officially available, and you can get it from the official release page on GitHub: https://github.com/QB64Team/qb64/releases/latest

Here is the full changelog: https://www.qb64.org/portal/changelog-for-v2-0/

Huge thanks to everyone involved in testing the latest dev builds so we could get to this milestone. Thanks to everyone for your continued support and interest in QB64.


r/qb64 • • Feb 28 '21

News QB64 v1.5 released!

Thumbnail
github.com
16 Upvotes

r/qb64 • • Jul 29 '21

News $Debug mode is coming soon to QB64 🥰🤩

15 Upvotes

r/qb64 • • Sep 20 '23

My text adventure framework gets a GUI

14 Upvotes

r/qb64 • • Feb 13 '19

Tutorial BabyShark.bas

Post image
14 Upvotes

r/qb64 • • Nov 20 '21

QB64 helped me rediscover some of my old GWBasic programming from the late 80s.

12 Upvotes

I discovered QB64 the other night when I was looking around for information on the old VB6 language. I was immediately interested because I first learned programming on the old GWBasic language in '86 and '87. C# is now my primary language.

I used to spend hours after school every day in the computer lab working on my own projects. The biggest one was a Bible verse program that used text files to store the different books. Again, this was in '86, before there was any Bible software. I didn't have any illusions about taking it to the market but it was a fun project for me at the time and I got plenty of practice working with text files and program flow.

I kept all my files from that time in my archives - I don't like deleting things permanently. After downloading QB64, I tried opening one of my old BAS files and remembered that I'd saved them in binary format instead of ASCII. Fortunately, I also still have a copy of GWBasic and was able to track down the commands for opening the files on a Windows 2000 virtual machine and re-saving them in ASCII.

I discovered that I'd actually done the last coding on the file in '92 - probably when I was unemployed for a time and was just playing around with code. Seeing my old code is a serious trip and QB64 makes it a lot easier to inspect it than the old GWBasic interpreter did. I was way too fond of combining lines with ":" and it's a serious mess of spaghetti despite my best intentions at the time. It's great to look at what I was doing back then, though, and I was surprised by how I started remembering the commands 30 years later.

I'm half tempted to go through my old code and clean it up in QB64 just for kicks. GWBasic wasn't able to compile and didn't even have commands to process mouse input. I'm glad to find a reddit group for QB64.


r/qb64 • • Apr 08 '19

QB64 v1.3 is finally out! Get it from the revamped www.qb64.org

Post image
12 Upvotes

r/qb64 • • Oct 10 '21

Tutorial Here's a detailed walkthrough of the new Debug features in QB64 v2.0

Thumbnail
youtu.be
11 Upvotes

r/qb64 • • Nov 23 '20

Tutorial Part 2: Pretentious not-yet-a-clone clone of Among Us in QB64

Thumbnail
youtube.com
11 Upvotes

r/qb64 • • Jan 19 '20

QB64 v1.4 Release Candidate up for testing

Thumbnail qb64.org
11 Upvotes

r/qb64 • • Sep 08 '21

SQLite in QB64

10 Upvotes

Since I do so much programming with SQL, I decided to try my hand at SQLite. SQLite uses SQL syntax to interact with a file as a database. It is used in millions of applications and software across the world. It is quicker than standard file operations and quicker than algorithms you could write yourself to get data from a file. I've started using it and all the testing so far has been magnificent. SQLite could be used to replace random access files and possibly even INIs. If you already know SQL then you will feel right at home using SQLite. I've kept the function names the same as the ones I'm using in my ODBC project and my MySQL rewrite.

Here is the code I've been using in my tests:

OPTION EXPLICIT
$NOPREFIX
$CONSOLE:ONLY
$EXEICON:'databases.ico'
ICON
 
CONST SQLITE_ABORT = 4
CONST SQLITE_AUTH = 23
CONST SQLITE_BUSY = 5
CONST SQLITE_CANTOPEN = 14
CONST SQLITE_CONSTRAINT = 19
CONST SQLITE_CORRUPT = 11
CONST SQLITE_DONE = 101
CONST SQLITE_EMPTY = 16
CONST SQLITE_ERROR = 1
CONST SQLITE_FORMAT = 24
CONST SQLITE_FULL = 13
CONST SQLITE_INTERNAL = 2
CONST SQLITE_INTERRUPT = 9
CONST SQLITE_IOERR = 10
CONST SQLITE_LOCKED = 6
CONST SQLITE_MISMATCH = 20
CONST SQLITE_MISUSE = 21
CONST SQLITE_NOLFS = 22
CONST SQLITE_NOMEM = 7
CONST SQLITE_NOTADB = 26
CONST SQLITE_NOTFOUND = 12
CONST SQLITE_NOTICE = 27
CONST SQLITE_OK = 0
CONST SQLITE_PERM = 3
CONST SQLITE_PROTOCOL = 15
CONST SQLITE_RANGE = 25
CONST SQLITE_READONLY = 8
CONST SQLITE_ROW = 100
CONST SQLITE_SCHEMA = 17
CONST SQLITE_TOOBIG = 18
CONST SQLITE_WARNING = 28
 
CONST SQLITE_INTEGER = 1
CONST SQLITE_FLOAT = 2
CONST SQLITE_BLOB = 4
CONST SQLITE_NULL = 5
CONST SQLITE_TEXT = 3
 
TYPE SQLITE_FIELD
    AS LONG TYPE
    AS STRING columnName, value
END TYPE
 
CONSOLETITLE "SQLite Test"
 
DECLARE DYNAMIC LIBRARY "sqlite3"
    FUNCTION sqlite3_open& (filename AS STRING, BYVAL ppDb AS OFFSET)
    SUB sqlite3_open (filename AS STRING, BYVAL ppDb AS OFFSET)
    FUNCTION sqlite3_prepare& (BYVAL db AS OFFSET, zSql AS STRING, BYVAL nByte AS LONG, BYVAL ppStmt AS OFFSET, BYVAL pzTail AS OFFSET)
    FUNCTION sqlite3_step& (BYVAL sqlite3_stmt AS OFFSET)
    FUNCTION sqlite3_changes& (BYVAL sqlite3_stmt AS OFFSET)
    FUNCTION sqlite3_column_count& (BYVAL sqlite3_stmt AS OFFSET)
    FUNCTION sqlite3_column_type& (BYVAL sqlite3_stmt AS OFFSET, BYVAL iCol AS LONG)
    FUNCTION sqlite3_column_name$ (BYVAL sqlite3_stmt AS OFFSET, BYVAL N AS LONG)
    FUNCTION sqlite3_column_text$ (BYVAL sqlite3_stmt AS OFFSET, BYVAL iCol AS LONG)
    FUNCTION sqlite3_column_bytes& (BYVAL sqlite3_stmt AS OFFSET, BYVAL iCol AS LONG)
    SUB sqlite3_finalize (BYVAL sqlite3_stmt AS OFFSET)
    SUB sqlite3_close (BYVAL db AS OFFSET)
END DECLARE
 
DIM SHARED AS OFFSET hSqlite, hStmt
DIM AS STRING sql
REDIM SHARED AS SQLITE_FIELD DB_Result(1 TO 1, 1 TO 1)
 
DIM AS STRING db: db = "test.db"
IF DB_Open(db) THEN
    DIM AS STRING conTitle: conTitle = "SQLite Test - " + db: CONSOLETITLE conTitle
    IF DB_QUERY("SELECT * FROM test") = SQLITE_OK THEN
        DIM AS LONG column, row
        FOR row = 1 TO UBOUND(DB_Result, 2)
            PRINT "Row"; row
            FOR column = 1 TO UBOUND(DB_Result, 1)
                PRINT , GetDataType(DB_Result(column, row).TYPE), DB_Result(column, row).columnName, DB_Result(column, row).value
            NEXT
        NEXT
    END IF
    'If DB_QUERY("INSERT INTO test(column2) VALUES ('And now, a fifth row!');") = SQLITE_OK Then
    '    Print DB_AffectedRows
    'End If
    'If DB_QUERY("UPDATE test SET column2 = 'And now, a fourth row!' WHERE column1 = '4';") = SQLITE_OK Then
    '    Print DB_AffectedRows
    'End If
END IF
 
DB_Close
 
FUNCTION DB_Open%% (sqlitedb AS STRING)
    IF sqlite3_open(sqlitedb, OFFSET(hSqlite)) = SQLITE_OK THEN DB_Open = -1 ELSE DB_Open = 0
END FUNCTION
 
SUB DB_Open (sqlitedb AS STRING)
    sqlite3_open sqlitedb, OFFSET(hSqlite)
END SUB
 
SUB DB_QUERY (sql_command AS STRING)
    IF sqlite3_prepare(hSqlite, sql_command, LEN(sql_command), OFFSET(hStmt), 0) = SQLITE_OK THEN
        DIM AS LONG colCount: colCount = sqlite3_column_count(hStmt)
        DIM AS LONG column, row, ret
        ret = sqlite3_step(hStmt)
        IF ret = SQLITE_ROW THEN
            DO
                row = row + 1
                FOR column = 0 TO colCount - 1
                    REDIM PRESERVE AS SQLITE_FIELD DB_Result(colCount, row)
                    DB_Result(column + 1, row).TYPE = sqlite3_column_type(hStmt, column)
                    DB_Result(column + 1, row).columnName = sqlite3_column_name(hStmt, column)
                    DB_Result(column + 1, row).value = sqlite3_column_text(hStmt, column)
                NEXT
                ret = sqlite3_step(hStmt)
            LOOP WHILE ret = SQLITE_ROW
        ELSE
            'do some error catching
        END IF
        sqlite3_finalize hStmt
    END IF
END SUB
 
FUNCTION DB_QUERY& (sql_command AS STRING)
    IF sqlite3_prepare(hSqlite, sql_command, LEN(sql_command), OFFSET(hStmt), 0) = SQLITE_OK THEN
        DIM AS LONG colCount: colCount = sqlite3_column_count(hStmt)
        DIM AS LONG column, row, ret
        ret = sqlite3_step(hStmt)
        IF ret = SQLITE_ROW THEN
            DB_QUERY = SQLITE_OK
            DO
                row = row + 1
                FOR column = 0 TO colCount - 1
                    REDIM PRESERVE AS SQLITE_FIELD DB_Result(colCount, row)
                    DB_Result(column + 1, row).TYPE = sqlite3_column_type(hStmt, column)
                    DB_Result(column + 1, row).columnName = sqlite3_column_name(hStmt, column)
                    DB_Result(column + 1, row).value = sqlite3_column_text(hStmt, column)
                NEXT
                ret = sqlite3_step(hStmt)
            LOOP WHILE ret = SQLITE_ROW
        ELSEIF ret = SQLITE_DONE THEN DB_QUERY = SQLITE_OK
        ELSE DB_QUERY = SQLITE_ERROR
            'do some error catching
        END IF
        sqlite3_finalize hStmt
    END IF
END FUNCTION
 
FUNCTION DB_AffectedRows&
    DB_AffectedRows = sqlite3_changes(hSqlite)
END FUNCTION
 
FUNCTION GetDataType$ (dataType AS LONG)
    SELECT CASE dataType
        CASE SQLITE_INTEGER
            GetDataType = "INTEGER"
        CASE SQLITE_FLOAT
            GetDataType = "FLOAT"
        CASE SQLITE_BLOB
            GetDataType = "BLOB"
        CASE SQLITE_NULL
            GetDataType = "NULL"
        CASE SQLITE_TEXT
            GetDataType = "TEXT"
    END SELECT
END FUNCTION
 
SUB DB_Close
    sqlite3_close hSqlite
END SUB

Links to the necessary files for testing:
https://drive.google.com/file/d/10tAcqDLgFJssP099v97NrrmU1V1Z_FdL/view?usp=sharing, https://drive.google.com/file/d/1hmTWAYCBqDByqMhw7mCd1swZ6WtepUMT/view?usp=sharing, https://drive.google.com/file/d/1xz7FyXODkzsSB0xmsp6AsIEsWN2a8rwL/view?usp=sharing


r/qb64 • • Mar 01 '21

News QB64 v1.5 New Features

Thumbnail
youtu.be
10 Upvotes

r/qb64 • • Jul 02 '20

Latest episode of QB64 Report now available. Listen to the Team interviewing Jared Hoffa, who wrote 486, a retro game, written in QB64, that is now available on Steam.

Thumbnail
podcast.qb64.org
10 Upvotes

r/qb64 • • Apr 09 '20

QB64 is the Cadillac of BASIC interpreters [131 SUBSCRIBER MILESTONE SPECIAL]

10 Upvotes

131 SUBSCRIBERS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

I thought I'd pay homage to the town of Cadillac, Michigan, as well as say the word Cadillac in terms of how QB64 is the top of the line of BASIC interpreters!

131 is a highway number near Cadillac, Michigan.


r/qb64 • • Oct 17 '21

News - New Version Version 2.0.1 released, with critical bug fix for Windows versions earlier than 10 and other fixes.

Thumbnail
github.com
9 Upvotes

r/qb64 • • Jun 05 '22

I just noticed that version 2.0.2 of QB64 has a new interface for selecting CODE PAGE 437 characters of IBM's Extended ASCII set!

Post image
8 Upvotes

r/qb64 • • Apr 24 '22

your ideal LOADING screen for video games to develop in QB64.

Post image
8 Upvotes

r/qb64 • • Feb 09 '22

r/QBmusic is a subreddit to share music compositions in using the PLAY command

Thumbnail reddit.com
8 Upvotes

r/qb64 • • Nov 05 '21

When programmers use to use the "Basic" language back in the day (early 80 or so) for your job

8 Upvotes

Hi, calling to all programmers that used "Basic" language (power basic, PDS, etc) for a living back when it was popular. What is your story? please list the program you made with it, the language that it was programmed in when you stop using it, and if the program is still active today (2021/2022). Thanks for your time.


r/qb64 • • Sep 06 '21

ODBC in QB64 (Windows 32 & 64 bit)

8 Upvotes

Working with ODBC connections in Windows since I work a lot with MySQL (and now Sybase). I've got some test code working very well that I'm going to eventually turn into a BI & BM library. I've only tested the code on Windows 10 and 11 with 64 bit and 32 bit QB64. DB_DetailResult won't be in the final library as it is just being used for testing to verify that the detailed data I'm storing in my "object" is correct.

Option Explicit
$NoPrefix
$Console:Only
$VersionInfo:Comments=Testing ODBC connections in Windows using QB64
$ExeIcon:'databases.ico'
Icon

Type SQL_FIELD
    As Integer type
    As Unsigned Integer size
    As Byte isNullable
    As Integer decimalDigits
    As String columnName, value
End Type

Const SQL_SUCCESS = 0

Dim Shared As Offset hEnv, hDbc, hStmt
ReDim Shared As SQL_FIELD DB_Result(1 To 1, 1 To 1)
Dim Shared As String ConnectionString
Dim As String datasource: datasource = "SpriggsyWinServer"

If DB_Open(datasource) Then
    If datasource <> "" Then
        Dim As String conTitle: conTitle = "ODBC Test - " + datasource: ConsoleTitle conTitle
    Else
        conTitle = "ODBC Test": ConsoleTitle conTitle
    End If
    If DB_QUERY("SELECT * FROM root.table1") = SQL_SUCCESS Then
        DB_DetailResult
    End If
    DB_Close
Else System
End If

Declare Dynamic Library "odbc32"
    Sub SQLAllocHandle (ByVal HandleType As Integer, Byval InputHandle As Offset, Byval OutputHandlePtr As Offset)
    Function SQLGetDiagRec%& (ByVal HandleType As Integer, Byval Handle As Offset, Byval RecNumber As Integer, Byval SQLState As Offset, Byval NativeErrorPtr As Offset, Byval MessageText As Offset, Byval BufferLength As Integer, Byval TextLengthPtr As Offset)
    Sub SQLSetEnvAttr (ByVal EnvironmentHandle As Offset, Byval Attribute As Long, Byval ValuePtr As Offset, Byval StringLength As Long)
    Function SQLDriverConnect%& (ByVal ConnectionHandle As Offset, Byval WindowHandle As Offset, InConnectionString As String, Byval StringLength1 As Integer, Byval OutConnectionString As Offset, Byval BufferLength As Integer, Byval StringLength2Ptr As Offset, Byval DriverCompletion As Unsigned Integer)
    Sub SQLPrepare (ByVal StatementHandle As Offset, StatementText As String, Byval TextLength As Long)
    Sub SQLExecute (ByVal StatementHandle As Offset)
    Function SQLExecute%& (ByVal StatementHandle As Offset)
    Sub SQLNumResultCols (ByVal StatementHandle As Offset, Byval ColumnCountPtr As Offset)
    Sub SQLDescribeCol (ByVal StatementHandle As Offset, Byval ColumnNumber As Unsigned Integer, Byval ColumnName As Offset, Byval BufferLength As Integer, Byval NameLengthPtr As Offset, Byval DataTypePtr As Offset, Byval ColumnSizePtr As Offset, Byval DecimalDigitsPtr As Offset, Byval NullablePtr As Offset)
    Function SQLFetch%& (ByVal StatementHandle As Offset)
    Function SQLGetData%& (ByVal StatementHandle As Offset, Byval ColOrParamNum As Unsigned Integer, Byval TargetType As Integer, Byval TargetValuePtr As Offset, Byval BufferLength As Offset, Byval StrLenOrIndPtr As Offset)
    Function SQLRowCount%& (ByVal StatementHandle As Offset, Byval RowCountPtr As Offset)
    Sub SQLFreeHandle (ByVal HandleType As Integer, Byval Handle As Offset)
    Sub SQLDisconnect (ByVal ConnectionHandle As Offset)
End Declare

Declare CustomType Library
    Function GetDesktopWindow%& ()
End Declare

Function DB_Open%% (dsn As String)
    Const SQL_HANDLE_ENV = 1
    Const SQL_HANDLE_DBC = 2
    Const SQL_HANDLE_STMT = 3
    Const SQL_DRIVER_COMPLETE = 1
    Const SQL_NULL_HANDLE = 0
    Const SQL_NTS = -3
    Const SQL_ATTR_ODBC_VERSION = 200
    Const SQL_OV_ODBC3 = 3~&

    Dim As Offset ret
    SQLAllocHandle SQL_HANDLE_ENV, SQL_NULL_HANDLE, Offset(hEnv)
    SQLSetEnvAttr hEnv, SQL_ATTR_ODBC_VERSION, SQL_OV_ODBC3, 0
    SQLAllocHandle SQL_HANDLE_DBC, hEnv, Offset(hDbc)
    Dim As String outstr: outstr = Space$(1024)
    Dim As Integer outstrlen
    If dsn = "" Then
        ret = SQLDriverConnect(hDbc, GetDesktopWindow, "", SQL_NTS, Offset(outstr), Len(outstr), Offset(outstrlen), SQL_DRIVER_COMPLETE)
    Else
        ret = SQLDriverConnect(hDbc, 0, "DSN=" + dsn + ";", SQL_NTS, Offset(outstr), Len(outstr), Offset(outstrlen), SQL_DRIVER_COMPLETE)
    End If
    ConnectionString = Mid$(outstr, 1, outstrlen)
    SQLAllocHandle SQL_HANDLE_STMT, hDbc, Offset(hStmt)
    If SQL_SUCCEEDED(ret) Then
        DB_Open = -1
    Else
        DB_Error "DB_Open", hDbc, SQL_HANDLE_DBC
        DB_Open = 0
    End If
End Function

Sub DB_Open (dsn As String)
    Const SQL_HANDLE_ENV = 1
    Const SQL_HANDLE_DBC = 2
    Const SQL_HANDLE_STMT = 3
    Const SQL_DRIVER_COMPLETE = 1
    Const SQL_NULL_HANDLE = 0
    Const SQL_NTS = -3
    Const SQL_ATTR_ODBC_VERSION = 200
    Const SQL_OV_ODBC3 = 3~&

    Dim As Offset ret
    SQLAllocHandle SQL_HANDLE_ENV, SQL_NULL_HANDLE, Offset(hEnv)
    SQLSetEnvAttr hEnv, SQL_ATTR_ODBC_VERSION, SQL_OV_ODBC3, 0
    SQLAllocHandle SQL_HANDLE_DBC, hEnv, Offset(hDbc)
    Dim As String outstr: outstr = Space$(1024 + 1)
    Dim As Integer outstrlen
    If dsn = "" Then
        ret = SQLDriverConnect(hDbc, GetDesktopWindow, "", SQL_NTS, Offset(outstr), Len(outstr), Offset(outstrlen), SQL_DRIVER_COMPLETE)
    Else
        ret = SQLDriverConnect(hDbc, 0, "DSN=" + dsn + ";", SQL_NTS, Offset(outstr), Len(outstr), Offset(outstrlen), SQL_DRIVER_COMPLETE)
    End If
    ConnectionString = Mid$(outstr, 1, outstrlen)
    SQLAllocHandle SQL_HANDLE_STMT, hDbc, Offset(hStmt)
    If Not (SQL_SUCCEEDED(ret)) Then
        DB_Error "DB_Open", hDbc, SQL_HANDLE_DBC
    End If
End Sub

Sub DB_QUERY (sql_command As String)
    Const SQL_CHAR = 1
    Const SQL_C_CHAR = SQL_CHAR
    Const SQL_NO_NULLS = 0
    Const SQL_NULLABLE = 1
    Const SQL_NULLABLE_UNKNOWN = 2
    Const SQL_NULL_DATA = -1
    Const SQL_NTS = -3

    Dim As Offset ret, execCode
    SQLPrepare hStmt, sql_command, SQL_NTS
    execCode = SQLExecute(hStmt)
    If SQL_SUCCEEDED(execCode) Then
        Dim As Integer columns
        SQLNumResultCols hStmt, Offset(columns)
        ret = SQLFetch(hStmt)
        Dim As Long row
        While SQL_SUCCEEDED(ret)
            Dim As Unsigned Integer i
            row = row + 1
            For i = 1 To columns
                Dim As Long indicator
                Dim As String buf: buf = Space$(4096 + 1)
                Dim As String columnName: columnName = Space$(128)
                Dim As Integer colNameLength, dataType, decimalDigits, nullable
                Dim As Unsigned Integer columnSize
                ret = SQLGetData(hStmt, i, SQL_C_CHAR, Offset(buf), Len(buf), Offset(indicator))
                If SQL_SUCCEEDED(ret) Then
                    ReDim Preserve As SQL_FIELD DB_Result(columns, row)
                    buf = Mid$(buf, 1, indicator)
                    If indicator = SQL_NULL_DATA Then buf = "NULL"
                    SQLDescribeCol hStmt, i, Offset(columnName), Len(columnName), Offset(colNameLength), Offset(dataType), Offset(columnSize), Offset(decimalDigits), Offset(nullable)
                    columnName = Mid$(columnName, 1, colNameLength)
                    DB_Result(i, row).type = dataType
                    DB_Result(i, row).size = columnSize
                    DB_Result(i, row).decimalDigits = decimalDigits
                    DB_Result(i, row).columnName = columnName
                    DB_Result(i, row).value = buf
                    Select Case nullable
                        Case SQL_NO_NULLS
                            DB_Result(i, row).isNullable = 0
                        Case SQL_NULLABLE
                            DB_Result(i, row).isNullable = -1
                    End Select
                End If
            Next
            ret = SQLFetch(hStmt)
        Wend
    Else
        DB_Error "DB_QUERY", hStmt, 3
    End If
End Sub

Function DB_QUERY%& (sql_command As String)
    Const SQL_CHAR = 1
    Const SQL_C_CHAR = SQL_CHAR
    Const SQL_NO_NULLS = 0
    Const SQL_NULLABLE = 1
    Const SQL_NULLABLE_UNKNOWN = 2
    Const SQL_NULL_DATA = -1
    Const SQL_NTS = -3
    Const SQL_SUCCESS = 0

    Dim As Offset ret, execCode
    SQLPrepare hStmt, sql_command, SQL_NTS
    execCode = SQLExecute(hStmt)
    If SQL_SUCCEEDED(execCode) Then
        Dim As Integer columns
        SQLNumResultCols hStmt, Offset(columns)
        ret = SQLFetch(hStmt)
        Dim As Long row
        While SQL_SUCCEEDED(ret)
            Dim As Unsigned Integer i
            row = row + 1
            For i = 1 To columns
                Dim As Long indicator
                Dim As String buf: buf = Space$(4096 + 1)
                Dim As String columnName: columnName = Space$(128)
                Dim As Integer colNameLength, dataType, decimalDigits, nullable
                Dim As Unsigned Integer columnSize
                ret = SQLGetData(hStmt, i, SQL_C_CHAR, Offset(buf), Len(buf), Offset(indicator))
                If SQL_SUCCEEDED(ret) Then
                    ReDim Preserve As SQL_FIELD DB_Result(columns, row)
                    buf = Mid$(buf, 1, indicator)
                    If indicator = SQL_NULL_DATA Then buf = "NULL"
                    SQLDescribeCol hStmt, i, Offset(columnName), Len(columnName), Offset(colNameLength), Offset(dataType), Offset(columnSize), Offset(decimalDigits), Offset(nullable)
                    columnName = Mid$(columnName, 1, colNameLength)
                    DB_Result(i, row).type = dataType
                    DB_Result(i, row).size = columnSize
                    DB_Result(i, row).decimalDigits = decimalDigits
                    DB_Result(i, row).columnName = columnName
                    DB_Result(i, row).value = buf
                    Select Case nullable
                        Case SQL_NO_NULLS
                            DB_Result(i, row).isNullable = 0
                        Case SQL_NULLABLE
                            DB_Result(i, row).isNullable = -1
                    End Select
                End If
            Next
            ret = SQLFetch(hStmt)
        Wend
    Else
        DB_Error "DB_QUERY", hStmt, 3
    End If
    DB_QUERY = execCode
End Function

Function DB_Esc$ (columnName As String)
    DB_Esc = "`" + columnName + "`"
End Function

Function DB_Q$ (value As String)
    DB_Q = "'" + value + "'"
End Function

Function DB_AffectedRows%&
    Dim As Offset rowCount
    Dim As Offset ret: ret = SQLRowCount(hStmt, Offset(rowCount))
    If SQL_SUCCEEDED(ret) Then DB_AffectedRows = rowCount
End Function

Sub DB_DetailResult
    Const SQL_DECIMAL = 3
    Const SQL_NUMERIC = 2
    Dim As Unsigned Integer row, column
    Print "Connection: "; ConnectionString
    For row = 1 To UBound(DB_Result, 2)
        Print "Row"; row
        For column = 1 To UBound(DB_Result, 1)
            Print "  "; column; GetDataType(DB_Result(column, row).type);
            If DB_Result(column, row).type = SQL_DECIMAL Or DB_Result(column, row).type = SQL_NUMERIC Then
                Print "("; Trim$(Str$(DB_Result(column, row).size)); ","; Trim$(Str$(DB_Result(column, row).decimalDigits)); ") ";
            Else
                Print "("; Trim$(Str$(DB_Result(column, row).size)); ") ";
            End If

            If DB_Result(column, row).isNullable = 0 Then
                Print DB_Result(column, row).columnName; " "; DB_Result(column, row).value; " "; "Not nullable"
            Else Print DB_Result(column, row).columnName; " "; DB_Result(column, row).value
            End If
        Next
    Next
End Sub

Sub DB_Close
    Const SQL_HANDLE_ENV = 1
    Const SQL_HANDLE_DBC = 2
    SQLDisconnect (hDbc)
    SQLFreeHandle SQL_HANDLE_DBC, hDbc
    SQLFreeHandle SQL_HANDLE_ENV, hEnv
End Sub

Function GetDataType$ (dataType As Integer)
    Const SQL_CHAR = 1
    Const SQL_C_CHAR = SQL_CHAR
    Const SQL_VARCHAR = 12
    Const SQL_LONGVARCHAR = -1
    Const SQL_WCHAR = -8
    Const SQL_WVARCHAR = -9
    Const SQL_WLONGVARCHAR = -10
    Const SQL_DECIMAL = 3
    Const SQL_NUMERIC = 2
    Const SQL_SMALLINT = 5
    Const SQL_INTEGER = 4
    Const SQL_REAL = 7
    Const SQL_FLOAT = 6
    Const SQL_DOUBLE = 8
    Const SQL_BIT = -7
    Const SQL_TINYINT = -6
    Const SQL_BIGINT = -5
    Const SQL_BINARY = -2
    Const SQL_VARBINARY = -3
    Const SQL_LONGVARBINARY = -4
    Const SQL_TYPE_DATE = 91
    Const SQL_TYPE_TIME = 92
    Const SQL_TYPE_TIMESTAMP = 93
    Const SQL_INTERVAL_MONTH = -81
    Const SQL_INTERVAL_YEAR = -80
    Const SQL_INTERVAL_YEAR_TO_MONTH = -82
    Const SQL_INTERVAL_DAY = -83
    Const SQL_INTERVAL_HOUR = -84
    Const SQL_INTERVAL_MINUTE = -85
    Const SQL_INTERVAL_SECOND = -86
    Const SQL_INTERVAL_DAY_TO_HOUR = -87
    Const SQL_INTERVAL_DAY_TO_MINUTE = -88
    Const SQL_INTERVAL_DAY_TO_SECOND = -89
    Const SQL_INTERVAL_HOUR_TO_MINUTE = -90
    Const SQL_INTERVAL_HOUR_TO_SECOND = -91
    Const SQL_INTERVAL_MINUTE_TO_SECOND = -92
    Const SQL_GUID = -11

    Select Case dataType
        Case SQL_CHAR, SQL_C_CHAR
            GetDataType = "CHAR"
        Case SQL_VARCHAR
            GetDataType = "VARCHAR"
        Case SQL_LONGVARCHAR
            GetDataType = "LONG VARCHAR"
        Case SQL_WCHAR
            GetDataType = "WCHAR"
        Case SQL_WVARCHAR
            GetDataType = "VARWCHAR"
        Case SQL_WLONGVARCHAR
            GetDataType = "LONGWVARCHAR"
        Case SQL_DECIMAL
            GetDataType = "DECIMAL"
        Case SQL_NUMERIC
            GetDataType = "NUMERIC"
        Case SQL_SMALLINT
            GetDataType = "SMALLINT"
        Case SQL_INTEGER
            GetDataType = "INTEGER"
        Case SQL_REAL
            GetDataType = "REAL"
        Case SQL_FLOAT
            GetDataType = "FLOAT"
        Case SQL_DOUBLE
            GetDataType = "DOUBLE PRECISION"
        Case SQL_BIT
            GetDataType = "BIT"
        Case SQL_TINYINT
            GetDataType = "TINYINT"
        Case SQL_BIGINT
            GetDataType = "BIGINT"
        Case SQL_BINARY
            GetDataType = "BINARY"
        Case SQL_VARBINARY
            GetDataType = "VARBINARY"
        Case SQL_LONGVARBINARY
            GetDataType = "LONG VARBINARY"
        Case SQL_TYPE_DATE
            GetDataType = "DATE"
        Case SQL_TYPE_TIME
            GetDataType = "TIME"
        Case SQL_TYPE_TIMESTAMP
            GetDataType = "TIMESTAMP"
        Case SQL_INTERVAL_MONTH
            GetDataType = "INTERVAL MONTH"
        Case SQL_INTERVAL_YEAR
            GetDataType = "INTERVAL YEAR"
        Case SQL_INTERVAL_YEAR_TO_MONTH
            GetDataType = "INTERVAL YEAR TO MONTH"
        Case SQL_INTERVAL_DAY
            GetDataType = "INTERVAL DAY"
        Case SQL_INTERVAL_HOUR
            GetDataType = "INTERVAL HOUR"
        Case SQL_INTERVAL_MINUTE
            GetDataType = "INTERVAL MINUTE"
        Case SQL_INTERVAL_SECOND
            GetDataType = "INTERVAL SECOND"
        Case SQL_INTERVAL_DAY_TO_HOUR
            GetDataType = "INTERVAL DAY TO HOUR"
        Case SQL_INTERVAL_DAY_TO_MINUTE
            GetDataType = "INTERVAL DAY TO MINUTE"
        Case SQL_INTERVAL_DAY_TO_SECOND
            GetDataType = "INTERVAL DAY TO SECOND"
        Case SQL_INTERVAL_HOUR_TO_MINUTE
            GetDataType = "INTERVAL HOUR TO MINUTE"
        Case SQL_INTERVAL_HOUR_TO_SECOND
            GetDataType = "INTERVAL HOUR TO SECOND"
        Case SQL_INTERVAL_MINUTE_TO_SECOND
            GetDataType = "INTERVAL MINUTE TO SECOND"
        Case SQL_GUID
            GetDataType = "GUID"
    End Select
End Function

Sub DB_Error (__fn As String, handle As Offset, __type As Integer)
    Const SQL_SUCCESS = 0
    Const MB_OK = 0 'OK button only
    Const MB_ICONEXCLAMATION = 48
    Dim As Long i, NativeError
    Dim As String SQLState: SQLState = Space$(5 + 1)
    Dim As String MessageText: MessageText = Space$(256 + 1)
    Dim As Integer TextLength
    Dim As Offset ret

    Do
        i = i + 1
        ret = SQLGetDiagRec(__type, handle, i, Offset(SQLState), Offset(NativeError), Offset(MessageText), Len(MessageText), Offset(TextLength))
        If SQL_SUCCEEDED(ret) Then
            MessageBox 0, "Error reported in " + __fn + ":" + Chr$(10) + Mid$(SQLState, 1, InStr(SQLState, Chr$(0)) - 1) + ":" + Trim$(Str$(i)) + ":" + Trim$(Str$(NativeError)) + ":" + Mid$(MessageText, 1, TextLength) + Chr$(0), "ODBC Error" + Chr$(0), MB_OK Or MB_ICONEXCLAMATION
        End If
    Loop While ret = SQL_SUCCESS
End Sub

Function SQL_SUCCEEDED& (rc As Offset)
    SQL_SUCCEEDED = (((rc) And (Not 1)) = 0)
End Function

$If MESSAGEBOX = UNDEFINED Then
    Declare Library
        Function MessageBox& (ByVal hWnd As _Offset, message As String, title As String, Byval uType As _Unsigned Long)
        Sub MessageBox (ByVal hWnd As _Offset, message As String, title As String, Byval uType As _Unsigned Long)
    End Declare
    $Let MESSAGEBOX = TRUE
$End If

r/qb64 • • Apr 21 '21

Recreating Bob Newby's code from Stranger Things in QB64

Thumbnail
specularrealms.com
8 Upvotes

r/qb64 • • Feb 05 '21

I made a (***very*** crude) window manager in QB64! =D Just thought I'd show it here, as I'm quite proud of it.

Post image
8 Upvotes

r/qb64 • • Jul 14 '20

Tutorial 🔊 Episode 4 of QB64 Report is now available. This time we talk to Luke, one of QB64's devs, and learn a lot about TCP/IP communications and Networking in QB64.

Thumbnail
qb64.buzzsprout.com
8 Upvotes

r/qb64 • • Feb 13 '20

News QB64 v1.4 released

Thumbnail
qb64.org
8 Upvotes

r/qb64 • • Apr 29 '22

QB64 Phoenix Edition Wiki, now we have a new Wiki to learn QB64 commands from!

Thumbnail
qb64phoenix.com
7 Upvotes