Some questions

newbie

Member
Licensed User
Hello,

i have download the trial version to take a look of basic4ppc.
Now i have as a newbie at this time two questions:

- can i call from the main application a form from a module ?
what is the syntax to do this ?

- is there a possibility to work with tables that can have one ore more
indexes ?

- how can i search for a record using a index

i use it for a application with more than 10.000 records and need speed.

kind regards from germany
 

Erel

Administrator
Staff member
Licensed User
Hi and welcome to Basic4ppc.
- Yes. For example if we have a module named 'Module1' and a form named 'Form1':
B4X:
Module1.Form1.Show
- Basic4ppc supports SQLite tables.
You can create any number of indexes in one table.
- Searching is done with a SELECT query.
The SQL language may look a little bit complex at the beginning however simple queries can be created very easily.
Here is a useful tutorial: SQL Tutorial
 

newbie

Member
Licensed User
more questiens

Thanks,
i have try to create a table like this

CREATE DATABASE MDEdb
CREATE TABLE ScanData
( Nummer Int Not NULL UNIQUE,
EAN varchar(13) UNIQUE,
Name varchar(30),
Groesse varchar(10),
Einheit varchar(4)
Bisher Int,
Menge Int
)
but i get comiler error ??

how can i find a list of datatype-names

kind regards
 

newbie

Member
Licensed User
Hallo Erel,

the version is 6.50

the code , see last mail

the compiler error was "inavlid Number of parenthesis"
for the line with the first Field-def

kind regards
 

Mr_Gee

Active Member
Licensed User
B4X:
CREATE DATABASE MDEdb

   CREATE TABLE ScanData
      (   Nummer  Int       Not NULL UNIQUE,
          EAN    varchar(13)   UNIQUE,
         Name   varchar(30),
         Groesse   varchar(10),
         Einheit   varchar(4)
         Bisher   Int,
         Menge   Int
      )
I think the problem lies with the "Create DB" command
The DB will be created automatically if the SQLite db cannot be found.

Personally I always create a DB with another (visual) SQLite manager
and then I don't need to sc**w around with the above commands.


Good Luck
 

newbie

Member
Licensed User
the problem is compiling the code
the compiler gives a error message "invalid number of parenthesis"
 

Erel

Administrator
Staff member
Licensed User
A string can't include more than a single line.
You only posted your SQL code so I'm not sure if that is the problem, or not.
A multiline string should be built with the concatenation character.
 

newbie

Member
Licensed User
Hi Erel,

that is the complete Code. Sorry, but i don't understand what you say.
when id do it in one line i get a normal syntax error.
what is the correct syntax to create a table, i don't found a example.

Sub Form1_Show
'create the Database and table
CREATE DATABASE MDEdb
CREATE TABLE MDEdb.ScanData
( Nummer Int Not NULL UNIQUE,
EAN varchar(13) UNIQUE,
Name varchar(30),
Groesse Real,
Einheit varchar(4),
Bisher Int,
Menge Int
)
End Sub


kind regards
 

Erel

Administrator
Staff member
Licensed User
You are confusing between Basic4ppc language and SQL language.
The way to work with SQL queries is to build a string that holds the query and then pass this string to a SQL Command object.

The first steps that are required when working with the SQL library are:
- Add a reference to SQLDesktop.dll and SQLDevice.dll.
- Add a Connection object and a Command object.
This is the code that builds your table (the program is attached):
B4X:
Sub Globals
    'Declare the global variables here.

End Sub

Sub App_Start
    connection.New1
    connection.Open("Data Source = " & AppPath & "\myDb.db")
    command.New1("",connection.Value)
    CreateTable
    
    'Show the table
    command.CommandText = "SELECT * FROM ScanData"
    command.ExecuteTable("table1",0)
    form1.Show
End Sub

Sub CreateTable
    command.CommandText = _
        "CREATE TABLE IF NOT EXISTS ScanData " & _
        "( Nummer Int Not NULL UNIQUE, " & _
        "EAN varchar(13) UNIQUE, " & _
        "Name varchar(30), " & _
        "Groesse Real, " & _
        "Einheit varchar(4), " & _
        "Bisher Int, " & _
        "Menge Int " & _
        ")"
    command.ExecuteNonQuery
End Sub
 
Top