[books] Pre-release of Chapter 5 of Rebol - A programmer's guide
[1/22] from: pwawood::gmail::com at: 1-Jul-2008 18:02
The pre-release of Rebol for pros, Chapter 5 of Rebol - A programmer's
guide is now available at http://www.lulu.com/content/2845102
It covers calling other programs and shared libraries, using MySQL
from Rebol CGI scripts and how to manage source code with the free
version of the Rebol pre-processor. All of these can be used from the
latest free versions of Rebol.
The chapter also includes a really enthusiastic introduction to IOS
and details of the data encryption features in Rebol/Command.
Regards
Peter Wood
[2/22] from: tim-johnsons::web::com at: 1-Jul-2008 9:46
On Tuesday 01 July 2008, Peter W A Wood wrote:
> The pre-release of Rebol for pros, Chapter 5 of Rebol - A programmer's
> guide is now available at http://www.lulu.com/content/2845102
<<quoted lines omitted: 6>>
> Regards
> Peter Wood
I understand that this is written for /command?
Is that correct.
thanks Peter
tim
[3/22] from: pwawood::gmail::com at: 2-Jul-2008 14:38
Tim
I'd say about 30% of the chapter relates to /Command, another 40% to
IOS and the remainder to /Core and /View.
The main topics relevant to the free versions are using MySQL from CGi
with Doc Kimbel's excellent MySQL scheme and using Prebol Version 1.0
(the free version). The introductions to 'call and 'load/library are
very brief.
Regards
Peter
On 2 Jul 2008, at 01:46, Tim Johnson wrote:
[4/22] from: tim-johnsons::web::com at: 2-Jul-2008 11:02
On Tuesday 01 July 2008, Peter W A Wood wrote:
> Tim
Thanks.
> I'd say about 30% of the chapter relates to /Command, another 40% to
> IOS and the remainder to /Core and /View.
Understood.
FYI: I only use /core because of my company's GPL/Open Source
mission. Have said that .....
> The main topics relevant to the free versions are using MySQL from CGi
> with Doc Kimbel's excellent MySQL scheme and
I've been using mysql-protocol (Mysql Scheme) and cgi for many years now. I
really like it, but I think that /command would bring some advantages, if
it can directly access the "C" API for MySQL.
Example: Using the mysql scheme on a tcp/ip connection, I have to code
the escaping of special characters for insert and updates and code the
unescaping of special characters for retrieval.
Using the C API from other scripting languages, the mysql_real_escape_string()
function handles the escaping _appropriate_ to the version, and
queries are similarly unescaped.
If command can do the same, that might be an advantage over the mysql scheme
protocol.
Tim
[5/22] from: pwawood:g:mail at: 3-Jul-2008 18:11
Tim
> I've been using mysql-protocol (Mysql Scheme) and cgi for many years
> now. I
<<quoted lines omitted: 11>>
> mysql scheme
> protocol.
The book doesn't go into such detail on /Command database access; it
is after all aimed at introducing Rebol to programmers.
Now that RT has included library access in the latest free versions,
wouldn't it be possible to enhance Doc's scheme to include the MySQL C
API functions (not withstanding any licence implications). Perhaps a
note to Doc himself might catch his interest.
Regards
Peter
[6/22] from: pwawood:gm:ail at: 3-Jul-2008 18:24
[mysql] Pre-release of Chapter 5 of Rebol - A programmer's guide
Tim
Immediately after sending this note, I saw a relevant comment from
Gabriele on the AltME Rebol 3. I'm including his comment here as it
has already been published on the web:
about escaping, Nenad's driver has such functions already, so i don't
see that as an advantage for the native driver. Qtask has a native
driver too (for speed reason with large record sets), but remember
that when you use the mysql c library either your app has to be GPL or
you need a license from MySQL (Qtask has a license).
I think the functions referred to by Gabriele are those mentioned in
13.2 of the Doc's mysql driver docs.
Regards
Peter
On 3 Jul 2008, at 18:11, Peter W A Wood wrote:
[7/22] from: petr::krenzelok::seznam::cz at: 3-Jul-2008 8:41
Re: [books] Pre-release of Chapter 5 of Rebol - A programmer's guide
Tim Johnson napsal(a):
> On Tuesday 01 July 2008, Peter W A Wood wrote:
>> Tim
<<quoted lines omitted: 18>>
> function handles the escaping _appropriate_ to the version, and
> queries are similarly unescaped.
I doubt that you would gain any speed linking to C. C is a trade-off.
Doc's scheme was proven to be even faster, than native one of Command.
As for Escaping chars, you could create either REBOL funcs, C func and
wrap it to REBOL, or wrap you mysql_real_escape_string() yourself, as
/library component is now being free. However - sending the query to DB
is hardly the main botleneck, isn't it?
-pekr-
[8/22] from: tim-johnsons:web at: 3-Jul-2008 7:21
On Wednesday 02 July 2008, Petr Krenzelok wrote:
pekr:
> I doubt that you would gain any speed linking to C. C is a trade-off.
> Doc's scheme was proven to be even faster, than native one of Command.
Good to hear.
> /library component is now being free.
Could you explain further. Do I take this to mean that /core
has access to shared libraries? Or are you referring to rebol3?
> However - sending the query to DB
> is hardly the main botleneck, isn't it?
Of course not.
Thanks
Tim
[9/22] from: dhsunanda:gma:il at: 3-Jul-2008 16:27
Tim:
> Could you explain further. Do I take this to mean that /core
> has access to shared libraries? Or are you referring to rebol3?
I think he;s referring to Core 2.7.6, released in March:
<http://www.rebol.net/upnews/0026.html>
It says:
> Release /library Component for Free
> The /library component is now included
> in the free distribution of REBOL.
Sunanda
[10/22] from: petr:krenzelok:seznam:cz at: 3-Jul-2008 17:26
Tim Johnson napsal(a):
> On Wednesday 02 July 2008, Petr Krenzelok wrote:
> pekr:
>
>> /library component is now being free.
>>
> Could you explain further. Do I take this to mean that /core
> has access to shared libraries? Or are you referring to rebol3?
>
Yes, when preparing 2.7.6 release, we asked Carl, if RT would release
library component for free, and he agreed. So - just download latest
REBOL and you've got /library wrapper available! Good news, isn't it? :-)
-pekr-
[11/22] from: tim-johnsons::web::com at: 3-Jul-2008 9:38
On Thursday 03 July 2008, Petr Krenzelok wrote:
> Tim Johnson napsal(a):
> > On Wednesday 02 July 2008, Petr Krenzelok wrote:
<<quoted lines omitted: 7>>
> library component for free, and he agreed. So - just download latest
> REBOL and you've got /library wrapper available! Good news, isn't it? :-)
Wham!
tj
[12/22] from: tim-johnsons::web::com at: 3-Jul-2008 17:18
On Thursday 03 July 2008, Sunanda wrote:
> Tim:
> > Could you explain further. Do I take this to mean that /core
> > has access to shared libraries? Or are you referring to rebol3?
>
> I think he;s referring to Core 2.7.6, released in March:
> <http://www.rebol.net/upnews/0026.html>
OK. Downloaded and untarred but:
Not much help in either the binary itself or the URL for
how to use.
On my machine:
>> res: load/library %/usr/lib/libmysqlclient.so.15
== ELF
>> probe res
ELF
== ELF
>>
;; DUH!
Any further docs anywhere?
thanks
Tim
[13/22] from: nick::guitarz::org at: 3-Jul-2008 22:55
The main docs:
http://rebol.com/docs/library.html
And probably too simple for your needs Tim, but for others looking for
a very basic introduction to using shared libraries (intended for
Windows users):
http://musiclessonz.com/rebol_tutorial.html#section-25
Quoting Tim Johnson <tim-johnsons-web.com>:
[14/22] from: petr::krenzelok::seznam::cz at: 4-Jul-2008 8:49
Tim Johnson napsal(a):
> On Thursday 03 July 2008, Sunanda wrote:
>> Tim:
<<quoted lines omitted: 16>>
> ELF
> == ELF
the same under windows and with different library:
->> do %sqlite.r
Script: "SQLite driver" (20-Feb-2007)
->> type? sqlite/*lib
== library!
->> probe sqlite/*lib
library
You have to look at docs, find your C API for your particular library
and create routine wrappers ....
-pekr-
[15/22] from: tim-johnsons:web at: 4-Jul-2008 7:50
On Thursday 03 July 2008, Petr Krenzelok wrote:
> You have to look at docs, find your C API for your particular library
> and create routine wrappers ....
It would be good to see an example. There's no docs with this distro,
and docs for ver 2.6 (as far as I can find) show no examples for
load/library.
thanks
tim
[16/22] from: petr:krenzelok:seznam:cz at: 4-Jul-2008 19:20
Tim Johnson napsal(a):
> On Thursday 03 July 2008, Petr Krenzelok wrote:
>> You have to look at docs, find your C API for your particular library
<<quoted lines omitted: 5>>
> thanks
> tim
huh? http://www.rebol.com/docs/library.html
-pekr-
[17/22] from: tim-johnsons:web at: 4-Jul-2008 9:48
On Friday 04 July 2008, Petr Krenzelok wrote:
> Tim Johnson napsal(a):
> > On Thursday 03 July 2008, Petr Krenzelok wrote:
<<quoted lines omitted: 7>>
> > tim
> huh? http://www.rebol.com/docs/library.html
Thanks. I figured it would be in the /command
docs ....
cheers
tim
[18/22] from: nick:guitarz at: 4-Jul-2008 11:34
Hmmm, I thought I posted that link several messages back... Anyway,
here's how to wrap functions from a library (from the other link in
that earlier message):
; to open the library:
lib: load/library %TheNameOfYour.library
; to wrap a function in the library:
your-rebol-function-name: make routine! [
return-value: [data-type!]
first-parameter [data-type!]
another-parameter [data-type!]
more-parameters [and-their-data-types!]
...
] lib "TheFunctionNameInsideThelibrary"
; to run the wrapped function in Rebol with your parameters:
your-rebol-function-name parameter1 parameter2 ...
; to free the library when done:
free lib
I'm not at all familiar with the MySQL api, but here's a quick example
of the mysql_real_connect function wrapped for Rebol. You'll need to
fix the datatypes (for example, I'm not sure what type mysql_init
returns for use as the first parameter "conn"), but this outline
should give you an idea of how to get started:
lib: load/library %/usr/lib/libmysqlclient.so.15
mysql-connect: make routine! [
return: [integer!]
parameter1 [int!] ; not sure of this type
parameter2 [string!]
parameter2 [string!]
parameter2 [string!]
parameter2 [string!]
parameter2 [int!]
parameter2 [string!]
parameter2 [int!] ; not sure of this type
] lib "mysql_real_connect"
; the "conn" variable below is gotten by running mysql_init
mysql-connect conn, "localhost" "root" "PASSWORD" "mysql" 0, "", 0
Quoting Tim Johnson <tim-johnsons-web.com>:
[19/22] from: nick::guitarz::org at: 4-Jul-2008 14:58
Oops, in copying and pasting from the C example, I included a bunch of
typos in that last post. Forgot to take out the commas here:
mysql-connect conn, "localhost" "root" "PASSWORD" "mysql" 0, "", 0
Should be more like:
mysql-connect conn "localhost" "root" "PASSWORD" "mysql" 0 "" 0
Also, the parameter names in the routine definition should be
different, and it should be integer! instead of int!:
mysql-connect: make routine! [
return: [integer!]
parameter1 [integer!] ; not sure of this type
parameter2 [string!]
parameter3 [string!]
parameter4 [string!]
parameter5 [string!]
parameter6 [integer!]
parameter7 [string!]
parameter8 [integer!]
] lib "mysql_real_connect"
Hehe, probably obvious typos, but just in case ... :)
Quoting Nick Antonaccio <nick-guitarz.org>:
[20/22] from: tim-johnsons::web::com at: 4-Jul-2008 16:53
On Friday 04 July 2008, Nick Antonaccio wrote:
> Hmmm, I thought I posted that link several messages back... Anyway,
> here's how to wrap functions from a library (from the other link in
<<quoted lines omitted: 32>>
> ; the "conn" variable below is gotten by running mysql_init
> mysql-connect conn, "localhost" "root" "PASSWORD" "mysql" 0, "", 0
Thanks Nick!
Tim
[21/22] from: dockimbel::free::fr at: 7-Jul-2008 23:58
Hi Tim,
My driver escapes special characters when using prepared statements (as
described here : http://softinnov.org/rebol/mysql-usage.html#sect6.2.).
This is the recommended way to create queries.
But if you're forming the sql queries by appending data to SQL strings,
it's up to you to correctly encode/escape data.
I should maybe expose the internal SQL encoding function, so it would be
available in global context for such use cases. I'll consider that for
the next version of the driver.
--
DocKimbel
Tim Johnson wrote :
[...]
[22/22] from: tim-johnsons::web::com at: 7-Jul-2008 15:37
On Monday 07 July 2008, DocKimbel wrote:
> Hi Tim,
<...>
Hi DocKimbel:
> But if you're forming the sql queries by appending data to SQL strings,
> it's up to you to correctly encode/escape data.
I generally do the above, however, I have one function that takes an already
prepared query. I'm still at ver. 1.1.1 of your scheme, will download 1.6
and implement.
thanks
tim
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted