r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[SQLite] C library embeddable DB .

Maxim
7-Nov-2006
[463]
It also seems as if Carl is talking about a generic DB layer, such 
as is defined in python.  so any db, could just implement a derivative 
of the base class and be compatible to some extent.
Louis
7-Nov-2006
[464]
This is probably a real dumb question, but what is the advantage 
of SQLite over say a REBOL object database?
Ashley
8-Nov-2006
[465]
Depends on the number and size of records you wish to handle, whether 
ACID is important to you, and whether you need SQL access or not.
Henrik
8-Nov-2006
[466]
Carl mentions paging. Does that not mean that you can have really 
big tables that are swapped to disk?
Louis
9-Nov-2006
[467]
is it possible to easily add a new column to a db table already populated 
with data without losing that data?
MikeL
9-Nov-2006
[468]
Louis, It's not on the SQL92 features not supported http://www.sqlite.org/omitted.html
 so it must support alters.
Louis
9-Nov-2006
[469]
Mike, thanks. I'll keep playing around with it then.
Ashley
9-Nov-2006
[470]
Yes, see http://www.sqlite.org/lang_altertable.html
Louis
9-Nov-2006
[471x3]
Thanks, Ashley.  But that website has a flaw; it can't be downloaded 
easily. It should be either one html page or else one pdf file.
Related: has anyone written a script to download a complete website?
I would like to download the complete sqlite website.
Pekr
9-Nov-2006
[474]
try some of wget tools (webget). IIRC there is even some rebol based 
one on rebol.org iirc?
Louis
9-Nov-2006
[475]
Can't find any. i wrote a crude one once, but can't find it on my 
harddrive.
Rebolek
9-Nov-2006
[476]
Louis: there's batch-download by Anton, try it - http://anton.wildit.net.au/rebol/util/batch-download.r
Will
9-Nov-2006
[477]
Louis: if you are on os x, this one work pretty neat http://www.hexcat.com/deepvacuum/index.html
, it will dl the whole site and rewrite urls to make them relative, 
or you coud try with acrobat pro if you want a pdf version of the 
site
Henrik
9-Nov-2006
[478]
if you can use non-rebol stuff, use wget. It's very effective at 
mirroring sites to a local drive.
Will
9-Nov-2006
[479]
and DeepVacuum is a GUI for wget ;-)
Anton
9-Nov-2006
[480]
batch-download is not suited for downloading a whole website. It 
doesn't do any spidering.
Louis
9-Nov-2006
[481]
Pekr, Rebolek, Will, and Henrik, thanks. I'm on XP.  Too bad. DeepVacuum 
looks nice.
Anton
9-Nov-2006
[482]
Well, I suppose if you do the spidering, you can supply the links 
to batch-download. Still, it's not designed for that. Better to get 
a specific tool for that.
Henrik
9-Nov-2006
[483x2]
wget is available for windows.
http://pages.interlog.com/~tcharron/wgetwin.html
Louis
9-Nov-2006
[485x2]
Thanks, Anton. I'm going to study your script for other uses later.
Henrik, I'm going to try wget. Thanks.
Henrik
9-Nov-2006
[487x3]
as long as you use wget in the same location as where you put your 
downloaded files temporarily, you don't need to set the environment 
variables.

Then it's just in a DOS prompt:

wget -r -l <depth> <some site>

And it will download the site to <some site>/ directory
depth is how deep links should be gathered for downloading. Values 
above 3 or 4 can be dangerous. :-)
wget is also very good at resuming downloads:

wget -c <very incredibly big file>
Anton
9-Nov-2006
[490]
It's probably much better than batch-download at resuming. I should 
study its source to see what it knows.
Henrik
9-Nov-2006
[491]
That's right. It's very rare that wget fails to resume a download.
Louis
9-Nov-2006
[492]
C:\.SQLite>wget -r -l 1 http://www.sqlite.com/index.html
--23:27:13--  http://www.sqlite.com:80/index.html
           => `www.sqlite.com/index.html'
Connecting to www.sqlite.com:80... connected!
HTTP request sent, awaiting response...
23:27:14 ERROR -1: Malformed status line.
Pekr
9-Nov-2006
[493]
:-) Do you really find anything so valuable on sqlite.com domain, 
that you need to grab their whole site? :-)
Henrik
9-Nov-2006
[494]
of course Louis runs into an error I've never seen before
Louis
9-Nov-2006
[495]
:>)  Just tired and playing around.
Henrik
9-Nov-2006
[496x3]
sqlite.com contains a general domain site.
you probably want sqlite.org
and it downloads fine here
Louis
9-Nov-2006
[499x3]
It does help to have the correct website.  :>)
It's working now. Thanks Henrik!
Now I've probably got my whole harddrive filled up.
Ashley
9-Nov-2006
[502]
A good entry point if you just want to grab the SQL syntax is: http://www.sqlite.org/lang.html
Louis
16-Nov-2006
[503x3]
What am I doing wrong here:

rebol []
do %sqlite.r
do %rebgui.r

if not exists? %id.txt [write %id.txt 1]

db: %indodex.db
either not exists? db [
    CONNECT/create/flat/direct/format db

    SQL "create table base (id, Nama, Alamat, Telefon, Handfon, Fax, 
    Email, Tgl_Nikah, Nota)"

    SQL "create table birthdays (id, Nama, Jenis, Hubungan, Tgl_Lahir, 
    Agama, Nota)"
][
    CONNECT/flat/direct/format db
]
unless value? 'ctx-rebgui [
	either exists? %rebgui-ctx.r [do %rebgui-ctx.r] [do %rebgui.r]
]
set-colors
tab-size: 120x55
fonts: reduce [font-sans-serif font-fixed font-serif "verdana"]
do show-cc: make function! [] [
display "IndoDex Ver. 1.0.1" [
    tab-panel #HW data [
        "Add" [

            label "Title:" priority: drop-list 30 #W "Pak" data ["Pak" "Ibu" 
            "Sdr." "Sdri." "Drs." "Dr." "Tuan" "Nyonya"] 20x5
            return
            label "Nama:" nama: field 
            return
            label "Alamat:" alamat: area 50x30
            return
            label "Telefon" telefon: field
            return
            label "Handfon" handfon: field
            return
            label "Fax:" fax: field
            return
            label "E-Mail:" email: field
            return
            label "Nota:" nota: area 50x30
            return
            button "Save" [
                (id: to-integer read %id.txt)

                SQL/flat/direct {insert into base values (id, Nama, Alamat, Telefon, 
                Handfon, Fax, Email, Tgl_Nikah, Nota)}
                (write %id.txt id)
                show-text ex-status "Saved"]
        ]
        "Edit" [
            
	]
	"Search" [
	]
    ]
]
]
do-events
I'm getting this:

** User Error: SQLite no such column: id
** Near: make error! reform ["SQLite" error]
>>
This doesn't work either:


 SQL ["insert into base values (?, ?, ?, ?, ?, ?, ?, ?, ?)" ID, Nama, 
 Alamat, Telefon, Handfon, Fax, Email, Tgl_Nikah, Nota]
Ashley
16-Nov-2006
[506]
Try reducing the block, as in:


 SQL reduce ["insert into base values (?, ?, ?, ?, ?, ?, ?, ?, ?)" 
 ID, Nama, Alamat, Telefon, Handfon, Fax, Email, Tgl_Nikah, Nota]
Louis
16-Nov-2006
[507x4]
Thanks, Ashley.  I just got called to dinner. When I get back I'll 
try that.
Ashley, I still can't get it to work.
Here's the latest version:

rebol []
do %sqlite.r
do %rebgui.r
unless value? 'ctx-rebgui [
	either exists? %rebgui-ctx.r [do %rebgui-ctx.r] [do %rebgui.r]
]
set-colors
tab-size: 120x55
fonts: reduce [font-sans-serif font-fixed font-serif "verdana"]

if not exists? %id.txt [write %id.txt 1]
i: to-integer read %id.txt
i: i - 1
either not exists? %indodex.db [
    CONNECT/create %indodex.db

    SQL "create table base (ID, Title, Nama, Alamat, Telefon, Handfon, 
    Fax, Email, Tgl_Nikah, Nota)"

    SQL "create table birthdays (ID, Nama, Jenis, Hubungan, Tgl_Lahir, 
    Agama, Nota)"
][
    CONNECT %indodex.db
]
do show-cc: make function! [] [
set-colors
display "IndoDex Ver. 1.0.1" [
            label 16 "ID:" id: text (to-string i)
            return

            label 16 "Title:" title: drop-list 30 #W "Pak" data ["Pak" "Ibu" 
            "Sdr." "Sdri." "Drs." "Dr." "Tuan" "Nyonya"] 20x5
            return
            label 16 "Nama:" nama: field 
            return
            label 16 "Alamat:" alamat: area 50x30
            return
            label 16 "Telefon:" telefon: field
            return
            label 16 "Handfon:" handfon: field
            return
            label 16 "Fax:" fax: fax: field
            return
            label 16 "E-Mail:" email: field
            return
            label 16 "Nota:" nota: area 50x30
            return
            button "Save" [

                ;UNCOMMENT THE FOLLOWING LINES AND YOU WILL SEE THEY DON'T WORK. 
                ANYBODY KNOW WHAT IS WRONG?

                ;SQL reduce ["insert into base values (?, ?, ?, ?, ?, ?, ?, ?, ?, 
                ?)" id/text, title/text, nama/text, alamat/text, telefon/text, handfon/text, 
                fax/text, email/text, tgl_nikah/text, nota/text]

                ;SQL {insert into base values ('Pak' 'Ibu' 'Sdr.' 'Sdri.' 'Drs.' 
                'Dr.' 'Tuan' 'Nyonya' 'Jonew')}
                (i: to-integer i)
                (i: i + 1)
                (write %id.txt i)
                (i: to-string i)
            ]
            button "GUI Info [

                print [id/text " " title/text " " nama/text " " alamat/text newline]
            ]
            button "DB Info" [
                print TABLES
                SQLite/col-info?: true
                print SQL "select * from base"
                print SQLite/columns
            ]
            button "Halt" [
                halt
            ]
            button "Quit" [
                quit
            ]
]
]
do-events
Click on the <DB Info> button, and you will see that the tables have 
been created. But I haven't been able to insert any data.


Another problem is that the id field doesn't advance to the next 
number.
Ashley
16-Nov-2006
[511x2]
You have a few errors in there.


 - your values are comma seperated (e.g. use SQL reduce ["..." val1 
 val2 ...] instead

 - tgl_nikah/text appears in your INSERT but isn't present in your 
 display
	- your "DB Info" button can use ... print ROWS "base"
ID field problem can be fixed by using code like:

	...
	id/text: form i: i + 1
	save %id.txt i
	show id

No need for parenthesis.