sql.Initialize (File.DirInternal, Starter.nomeDB, True)
Dim cmd As String
cmd = "PRAGMA foreign_keys = ON"
sql.ExecNonQuery(cmd)
'
cmd = "PRAGMA auto_vacuum = '1'"
sql.ExecNonQuery(cmd)
cmd=$"create table if not exists fornitori (
"id" INTEGER,
"nome" TEXT
)"$
sql.ExecNonQuery(cmd)
'
'posizione: 0=articolo NON preferito | 1=articolo preferito
cmd=$"create table if not exists articoli (
"id" INTEGER,
"codice" TEXT,
"descrizione" TEXT,
"peso" TEXT,
"idfornitore" INTEGER,
"posizione" INTEGER,
"note" TEXT,
"unita" TEXT,
"idcliente" TEXT)"$
sql.ExecNonQuery(cmd)
'
cmd = "pragma table_info('articoli')"
Dim rs As Cursor
rs = sql.ExecQuery(cmd)
Dim note_esiste As Boolean = False
Dim unita_esiste As Boolean = False
Dim id_cliente As Boolean = False
For i = 0 To rs.RowCount - 1
rs.Position = i
If rs.GetString("name") = "note" Then
note_esiste = True
End If
If rs.GetString("name") = "unita" Then
unita_esiste = True
End If
If rs.GetString("name") = "idcliente" Then
id_cliente = True
End If
Next
rs.Close
If note_esiste = False Then
cmd = "alter table articoli add note TEXT"
sql.ExecNonQuery (cmd)
End If
'
If unita_esiste = False Then
cmd = "alter table articoli add unita TEXT"
sql.ExecNonQuery (cmd)
End If
'
If id_cliente = False Then
cmd = "alter table articoli add idcliente text"
sql.ExecNonQuery (cmd)
End If
'
cmd=$"create table if not exists preordine (
"idart" INTEGER,
"qta" TEXT,
"annotazioni" TEXT
)"$
sql.ExecNonQuery(cmd)
'
cmd = $"CREATE UNIQUE INDEX IF NOT EXISTS "xpreordine" ON "preordine" ("idart")"$
sql.ExecNonQuery(cmd)
'
cmd = $"CREATE TABLE if not exists ordini (
"id" INTEGER Not Null UNIQUE,
"idcliente" TEXT,
"dataord" TEXT,
"annotazioni" TEXT,
"inviato" INTEGER,
"idordine" INTEGER,
PRIMARY KEY("id" AUTOINCREMENT)
)"$
sql.ExecNonQuery(cmd)
''''''''''''''''''''''''''''''''''''''
cmd = "pragma table_info('ordini')"
Dim rs As Cursor
rs = sql.ExecQuery(cmd)
Dim idOrdine_esiste As Boolean = False
For i = 0 To rs.RowCount - 1
rs.Position = i
If rs.GetString("name") = "idordine" Then
idOrdine_esiste = True
End If
Next
rs.Close
If idOrdine_esiste = False Then
cmd = "alter table ordini add idordine INTEGER"
'Log(cmd)
sql.ExecNonQuery (cmd)
End If
''''''''''''''''''''''''''''''''''''''
cmd=$"create table if not exists rigoordini (
"id" INTEGER Not Null UNIQUE,
"idordini" INTEGER,
"idcliente" TEXT,
"idart" INTEGER,
"qta" TEXT,
"annotazioni" TEXT,
"inviato" INTEGER,
"unita" TEXT,
PRIMARY KEY("id" AUTOINCREMENT)
)"$
sql.ExecNonQuery(cmd)
'
cmd = $"create table if not exists unita (
"id" INTEGER,
"um" text)"$
sql.ExecNonQuery(cmd)
'
cmd = $"CREATE TABLE if not exists progressivo (
"id" INTEGER Not Null UNIQUE,
PRIMARY KEY("id" AUTOINCREMENT)
)"$
sql.ExecNonQuery(cmd)
sql.Close