Page 1 of 1

SQLite Problem

Posted: Tue Mar 12, 2024 10:47 pm
by davidKain
Greetings!

Long time VBA / VB6 coder but am new to PureBasic.

I am taking a look at the "Databases" tutorial and even though I normally use MySQL and not SQLite, I figured to try to follow the steps and get a hang of things before migrating over to MySQL.

I'm trying to use the code provided in the tutorial to create a new database. I copy and pasted the Create SQL directly from DB Browser so I'm confident that my syntax is not the issue here.

Code: Select all

CREATE TABLE "servers" (
	"serverid"	INTEGER,
	"srvmachinename"	TEXT,
	"srvOS"	TEXT,
	"srvIP4"	TEXT,
	"adminuser"	TEXT,
	"adminpass"	TEXT,
	"status"	INTEGER NOT NULL DEFAULT 0,
	PRIMARY KEY("serverid")
)
When I paste it into Pure Basic, the first error I get is: 'SERVERS' IS NOT A VALID OPERATOR

Ok so the whole single quote double quote thing is going to take some getting used to.

But when I replace the CheckDatabaseUpdate line with this:

Code: Select all

CheckDatabaseUpdate(0, "CREATE TABLE 'servers' ('serverid' INTEGER, 'srvmachinename' TEXT, 'srvOS' TEXT, 'srvIP4' TEXT, 'adminuser' TEXT, 'adminpass'	TEXT, 'status' INTEGER Not NULL Default 0, PRIMARY KEY('serverid'))"
I get the error: SYNTAX ERROR

Any help would be appreciated!

Re: SQLite Problem

Posted: Tue Mar 12, 2024 11:09 pm
by normeus
The last double quote is in the wrong place:

Code: Select all

CheckDatabaseUpdate(0, "CREATE TABLE 'servers' ('serverid' INTEGER, 'srvmachinename' TEXT, 'srvOS' TEXT, 'srvIP4' TEXT, 'adminuser' TEXT, 'adminpass'	TEXT, 'status' INTEGER Not NULL Default 0, PRIMARY KEY('serverid')")

Take a look at blueznl's great tutorial for PureBasic, he has a lot of examples:

https://www.ninelizards.com/purebasic/index.htm

Norm.

Re: SQLite Problem

Posted: Tue Mar 12, 2024 11:22 pm
by davidKain
Thanks, Norm. Honestly, with my amount of experience there was no excuse for that oversight. It was 100% "I'm so great, it must be this new program that is wrong"

After changing it to this, everything works as expected

Code: Select all

CheckDatabaseUpdate(0, "CREATE TABLE 'servers' ('serverid' INTEGER, 'srvmachinename' TEXT, 'srvOS' TEXT, 'srvIP4' TEXT, 'adminuser' TEXT, 'adminpass'	TEXT, 'status' INTEGER Not NULL Default 0, PRIMARY KEY('serverid'))")