' MySQL Test Program
IMPORT mysql.bas
dbh = mysql::RealConnect("localhost","root","PASSWORD","classicmodels")
mysql::query(dbh,"SELECT * FROM products LIMIT 25")
WHILE mysql::FetchHash(dbh,column)
PRINT column{"productCode"}," - ",column{"productName"}," - ",FORMAT("%~$###.00~",column{"MSRP"}),"\n"
WEND
PRINTNL
PRINT "The database handle is: ",dbh,"\n"
PRINT "Affected rows by SELECT: ",mysql::AffectedRows(dbh),"\n"
PRINT "Character set name is: ",mysql::CharacterSetName(dbh),"\n"
PRINT "Last error is: ",mysql::ErrorMessage(dbh),"\n"
PRINT "Client info is: ",mysql::GetClientInfo(),"\n"
PRINT "Host info is: ",mysql::GetHostInfo(dbh),"\n"
PRINT "Proto info is: ",mysql::GetProtoInfo(dbh),"\n"
PRINT "Server info is: ",mysql::GetServerInfo(dbh),"\n"
PRINT "PING result: ",mysql::Ping(dbh),"\n"
PRINT "Thread ID: ",mysql::ThreadId(dbh),"\n"
PRINT "Status is: ",mysql::Stat(dbh),"\n"
mysql::Close(dbh)
' ScriptBasic AJAX & MySQL
IMPORT cgi.bas
cgi::Header 200,"text/html"
cgi::FinishHeader
PRINT """
<html>
<head>
<script>
function showItems(str) {
if (str == "") {
document.getElementById("results").innerHTML = "";
return;
} else {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("results").innerHTML = this.responseText;
}
};
xmlhttp.open("GET","/home/qbo/getitems.sb?q="+str,true);
xmlhttp.send();
}
}
</script>
</head>
<body>
<form>
<select name="items" onchange="showItems(this.value)">
<option value="">Product Line</option>
<option value="Classic Cars">Classic Cars</option>
<option value="Motorcycles">Motorcycles</option>
<option value="Planes">Planes</option>
<option value="Ships">Ships</option>
<option value="Trains">Trains</option>
<option value="Trucks and Buses">Trucks and Buses</option>
<option value="Vintage Cars">Vintage Cars</option>
</select>
</form>
<br>
<div id="results"></div>
</body>
</html>
"""
' AJAX - getitems.sb
IMPORT cgi.bas
IMPORT mysql.bas
cgi::Header 200,"text/html"
PRINT """
<!DOCTYPE html>
<html>
<head>
<style>
table {
width: 100%;
border-collapse: collapse;
}
table, td, th {
border: 1px solid black;
padding: 5px;
}
th {text-align: left;}
</style>
</head>
<body>
"""
product_line = cgi::GetParam("q")
dbh = mysql::RealConnect("localhost","USER","PASSWORD","classicmodels")
mysql::query(dbh,"SELECT * FROM products WHERE productLine = '" & product_line & "'")
PRINT """
<table>
<tr>
<th>Product Code</th>
<th>Product Line</th>
<th>Product Vendor</th>
<th>Product Name</th>
<th>In Stock</th>
<th>Cost</th>
<th>MSRP</th>
</tr>
"""
WHILE mysql::FetchHash(dbh,column)
PRINT " <tr>\n"
PRINT " <td>", column{"productCode"}, "</td>\n"
PRINT " <td>", column{"productLine"}, "</td>\n"
PRINT " <td>", column{"productVendor"}, "</td>\n"
PRINT " <td>", column{"productName"}, "</td>\n"
PRINT " <td align=\"right\">", column{"quantityInStock"}, "</td>\n"
PRINT " <td align=\"right\">", FORMAT("%~$###.00~",column{"buyPrice"}), "</td>\n"
PRINT " <td align=\"right\">", FORMAT("%~$###.00~",column{"MSRP"}), "</td>\n"
PRINT " </tr>\n"
WEND
PRINT """
</table>
</body>
</html>
"""
mysql::Close(dbh)
' SBT Demo
IMPORT sbt.sbi
sb_code = """
FUNCTION prtvars(a, b, c)
PRINT a,"\\n"
PRINT FORMAT("%g\\n", b)
PRINT c,"\\n"
prtvars = "Function Return"
END FUNCTION
a = 0
b = 0
c = ""
"""
sb = SB_New()
SB_Configure sb, "C:/Windows/SCRIBA.INI_32"
SB_Loadstr sb, sb_code
SB_NoRun sb
' Call function before running script
funcrtn = SB_CallSubArgs(sb,"main::prtvars", 123, 1.23, "One,Two,Three")
PRINT funcrtn,"\n"
' Run script initializing globals
SB_Run sb, ""
' Assign variables values
SB_SetInt sb, "main::a", 321
SB_SetDbl sb, "main::b", 32.1
SB_SetStr sb, "main::c", "Three,Two,One" & CHR(0)
' Call function again with variables assigned in the previous step
SB_CallSubArgs sb, "main::prtvars", _
SB_GetVar(sb, "main::a"), _
SB_GetVar(sb, "main::b"), _
SB_GetVar(sb, "main::c")
SB_Destroy sb
' SBT Main
IMPORT mt.sbi
IMPORT sbt.sbi
SB_ThreadStart("sbt_thread.sb", "","C:/Windows/SCRIBA.INI")
FOR x = 1 TO 10
PRINT "M:",x,"\n"
sb_msSleep(20)
NEXT
SB_msSleep(1000)
PRINT "Thread ",mt::GetVariable("thread_status"),"\n"
' SBT Thread
IMPORT mt.sbi
IMPORT sbt.sbi
FOR x = 1 TO 10
PRINT "T:",x,"\n"
SB_msSleep(20)
NEXT
mt::SetVariable "thread_status","Completed"
SB_ThreadEnd
' OpenWeather - cURL & JSON Example
IMPORT curl.sbi
IMPORT webext.sbi
place = COMMAND()
ch = curl::init()
curl::option(ch, "URL", "http://api.openweathermap.org/data/2.5/weather?q=" & place & "&units=imperial&appid=APP KEY")
curl::option(ch, "CUSTOMREQUEST", "GET")
json = curl::perform(ch)
curl::finish(ch)
PRINT json,"\n\n"
web::json2sba(json)
web::sbadump(json)
PRINT "\nTempreture: ", json{"main"}{"temp"}, " F\n"
PRINT "Date: ", FORMATDATE("MM/DD/YEAR 0H:0m:0s",json{"dt"} + json{"timezone"}),"\n"
END
SPLIT "1,2,3" BY "," TO a,b,cSPLITA "1,2,3" BY "," TO aeval_str = "This is an example string that will be searched by the LIKE function."
IF eval_str LIKE "*example * *" THEN
PRINT JOKER(2),"\n"
END IF
a = 1
IF a = 1 THEN
PRINT "a = 1\n"
ELSE IF a = 2 THEN
PRINT "a = 2\n"
ELSE
PRINT "a not in range\n"
END IF
' This is a single line comment.
'"""
This is a
multi-line comment
"""
PRINT "Hello, World!","\n"
10 LET A$="Hello World!"
20 PRINT A$,"\n"
30 END
' COM/OLE Automation Extension Module Import
GLOBAL CONST :CALL = 1
GLOBAL CONST :GET = 2
GLOBAL CONST :LET = 4
GLOBAL CONST :SET = 8
MODULE COM
DECLARE SUB ::CREATE ALIAS "CreateObject" LIB "com"
DECLARE SUB ::CBN ALIAS "CallByName" LIB "com"
DECLARE SUB ::RELEASE ALIAS "ReleaseObject" LIB "com"
DECLARE SUB ::GHO ALIAS "GetHostObject" LIB "com"
DECLARE SUB ::GHS ALIAS "GetHostString" LIB "com"
DECLARE SUB ::SVT ALIAS "ShowVariantType" LIB "com"
DECLARE SUB ::TN ALIAS "TypeName" LIB "com"
DECLARE SUB ::DI ALIAS "DescribeInterface" LIB "com"
DECLARE SUB ::CB ALIAS "SBCallBack" LIB "com"
END MODULE
a = 1
b = 2
c = "3"
d = "4"
PRINT a + b
PRINT a & b
PRINT c + d
PRINT c & d
a[0] = "Hello"
a[1] = 123.45a[100] = 100
PRINT LBOUND(a)
PRINT UBOUND(a)
a[50] = 50
PRINT LBOUND(a)
PRINT UBOUND(a)


