[Gambas-user] Primary Key missing?

Caveat Gambas at ...1950...
Fri Nov 26 09:42:03 CET 2010


> by the way... i found that i wasn't able to even find a command to
edit
> > a record in terminal; i wanted to proof if the sqlite3 program with the
> > same commands would tell me the same...
> 

Use sqlite, specify the name of the database on the command line...

$ sqlite mytest.db
SQLite version 2.8.17
Enter ".help" for instructions
sqlite> create table test(id integer primary key, name text);
sqlite> insert into test (id, name) values (1, "Aaron");
sqlite> insert into test (id, name) values (2, "Zacharias");
sqlite> select * from test;
1|Aaron
2|Zacharias
sqlite> update test set name = "Adam" where id = 1;
sqlite> select * from test;
1|Adam
2|Zacharias
sqlite> .quit
$


If you don't have sqlite installed, it'll moan at you:

$ sqlite
The program 'sqlite' is currently not installed.  You can install it by
typing:
sudo apt-get install sqlite

So, do as it says (this is Ubuntu, ymmv):

$ sudo apt-get install sqlite

Regards,
Caveat

On Fri, 2010-11-26 at 00:03 +0100, Benoît Minisini wrote:
> > hello,
> > 
> > prooving my sqlite code, i have several buttons on a form, whose subs
> > should do the same work in different ways (one just using Exec() method,
> > the other does all work with the gambas objects (editing fields etc.)).
> > 
> > after this code:
> > 
> > Button2_Click:
> > 
> >    DIM hResult AS Result
> > 
> >    hConnection.Exec("create table test(id integer primary key, name
> > varchar(10));")
> >    hConnection.Exec("insert into test(name) values(\"Aaron\");")
> >    hConnection.Exec("insert into test(name) values('Zacharias');")
> > 
> >    '1|Aaron
> >    '2|Zacharias
> > 
> > i have another button which should edit this table:
> > 
> >    DIM hResult AS Result
> > 
> >    hResult = hConnection.Edit("test", "name=&1", "Aaron")
> >    hResult["name"] = "Adam"
> >    hResult.Update()
> > 
> > 
> > but in the line where the Edit()-function is used, i get the error that
> > there is no primary key in my table but didn't i specify one creating
> > the table?
> > 
> > by the way... i found that i wasn't able to even find a command to edit
> > a record in terminal; i wanted to proof if the sqlite3 program with the
> > same commands would tell me the same...
> > 
> > regards,
> > tobi
> > 
> 
> The syntax I know for sqlite is:
> 
> create table test(id integer, name varchar(10), primary key(id))
> 
> Try to create table by using the Table class, and not the Exec() method.
> 
> Otherwise, send me your sqlite database so that I look at it.
> 
> Regards,
> 






More information about the User mailing list