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

World: r3wp

[MySQL]

Pekr
9-Jan-2006
[501x5]
Doc, are you sure your 'docode table is ok? I mean defs/client ....

client [
			long-password		1		; new more secure passwords
			found-rows			2		; Found instead of affected rows
			long-flag			4		; Get all column flags
			connect-with-db		8		; One can specify db on connect
			no-schema			16		; Don't allow db.table.column
			compress			32		; Can use compression protcol
			odbc				64		; Odbc client
			local-files			128		; Can use LOAD DATA LOCAL
			ignore-space		256		; Ignore spaces before '('
			change-user			512		; Support the mysql_change_user()
			interactive			1024	; This is an interactive client
			ssl					2048	; Switch to SSL after handshake
			ignore-sigpipe		4096	; IGNORE sigpipes
			transactions		8196	; Client knows about transactions
		]

While in protocol description, there is:

MySQL uses the following codes:
Capability name	Value	Meaning
LONG_PASSWORD	1	New more secure passwords
FOUND_ROWS	2	Found instead of affected rows
LONG_FLAG	4	Get all column flags
CONNECT_WITH_DB	8	One can specify db on connect
NO_SCHEMA	16	Don't allow database.table.column
COMPRESS	32	Can use compression protocol
ODBC	64	ODBC client
LOCAL_FILES	128	Can use LOAD DATA LOCAL
IGNORE_SPACE	256	Ignore spaces before '('
PROTOCOL_41	512	Support the 4.1 protocol
INTERACTIVE	1024	This is an interactive client
SSL	2048	Switch to SSL after handshake
IGNORE_SIGPIPE	4096	IGNORE sigpipes
TRANSACTIONS	8192	Client knows about transactions
SECURE_CONNECTION	32768	New 4.1 authentication
MULTI_STATEMENTS	65536	Multi-statement support
MULTI_RESULTS	131072	Multi-results
ah, extended the table and it shows:

----- Server ------
Version: 5.0.18-nt
Protocol version: 10
Thread ID: 36
Crypt Seed: iR=xh!fb
Capabilities: [
    long-flag
    connect-with-db
    compress
    protocol-41
    transactions
    secure-connection
]
newer version uploaded - now you can see there is protocol-41 flag, 
as well as secure-connection, according to which you can decide new 
auth. method was used imo ...
enough for today :-)
so, if you don't confirm there were changes in low-level protocol 
handling (reading, sending, flushing etc. code), then I can adapt 
the code to automatically distinguish for old/new auth scheme and 
respond accordingly. That could be some intermediate version for 
ppl to use ...
Dockimbel
10-Jan-2006
[506]
My old MySQL code is inpired by mm_mysql driver (now obsolete). The 
driver source code in C# you're pointing too is inspired by later 
evolutions of the mm_mysql driver.
Pekr
10-Jan-2006
[507x2]
so what is your opinion on the stack?
I think, that with "my" latest version, I now only need to distinguish 
authentication mode ... and to call scramble-long accordingly ....
Dockimbel
10-Jan-2006
[509]
MySQL server protocol has changed since 4.1.0 (with a big evolution 
starting from 4.1.1) and is not compatible with the older protocol. 
Strangely, server v5 allow clients to connect with the older (pre-4.1) 
protocol providing the good flags...(that's odd). Need more investigation 
to see if the old driver can still be used reliably with v5.
Pekr
10-Jan-2006
[510x3]
maybe better as a refinement of scramble itself ...
that is what I wanted to ask - did it really change?
I thought there is v9 and v10 protocols, and that only change was 
for auth. scheme ...
Dockimbel
10-Jan-2006
[513x2]
From 4.1.1, there's a lot of changes in the protocol, mainly a lot 
of new fields.
The protocol number hasn't been incremented, the server and client 
code in libmysql is messy...
Pekr
10-Jan-2006
[515x3]
so this is not accurate? http://www.redferni.uklinux.net/mysql/MySQL-Protocol.html
it seems to me as proper description of all communication phases 
...
well - so why it works so far for me?
Dockimbel
10-Jan-2006
[518]
yes it is, AFAICT. But it's protocol 4.1.1+, not the old one that 
is implemented in my driver.
Pekr
10-Jan-2006
[519x3]
aha, so actually what I did is that I extended parser for greetings 
phase, and also updated some locals table, watching carefully where 
such items are used - so far so good ...
I would be able to write it according to specs imo according to above 
protocol, but - I don't understand rebol port model, so :-(
and also - I would fire all old scrambler :-) but then old pre 4.11 
users would be at ends :-)
Dockimbel
10-Jan-2006
[522]
The server has still the support code for all protocol versions. 
That's why the old code is working, but according to the flags, (especially 
protocol_41), it should have rejected your connection. That's why 
I found it odd that your code was working. Anyway, let try to use 
this to make it work with the older code.
Pekr
10-Jan-2006
[523]
or do you think that checksum/secure could be used even for older 
mysql versions? I wonder if their scheme used sha1 in old days?
Dockimbel
10-Jan-2006
[524]
no, it wasn't 'sha1, it was a "poor man" hashing method.
Pekr
10-Jan-2006
[525]
I think I know why ... maybe :-) ..... simply put, I don't send protocol_41 
back after the greetings phase ...
Dockimbel
10-Jan-2006
[526]
Yes, I guess that's the trigger.
Pekr
10-Jan-2006
[527x2]
hmm, I will try to change that here :-)
latest version: http://www.rebol.cz/mysql/mysql-protocol-new.r
Dockimbel
10-Jan-2006
[529x2]
Ok, I'll make some changes to your code to make it work properly 
with 3.x and 4.1.x+ versions, then I'll launch my unit tests and 
see if it  is ok.
Your code doesn't deal with empty passwords, I'll fix that.
Pekr
10-Jan-2006
[531]
I know ... thanks ....!!!
Dockimbel
10-Jan-2006
[532x4]
New My
New MySQL driver version 1.0.0 supporting server v4.1.1+ : http://softinnov.org/tmp/mysql-protocol.r
This is a beta release, please report here any bugs.
This driver has not been tested with server version 3.x.
Dockimbel
11-Jan-2006
[536]
Softinnov.org was down for a couple of hours for server PSU replacement. 
The download link works now again.
Coccinelle
12-Jan-2006
[537]
Dock, if you publish a new version of mysql-protocol.r, it's time 
to make the correction of the bug in the init function, the longlong 
conversion and in the data reading initialization.
Pekr
12-Jan-2006
[538x3]
what bugs?
have you any fixes?
what is wrong with init, longlong conversion and in data reading 
initialisation in particular?
Coccinelle
12-Jan-2006
[541]
The init function fails with this for eaxample :

   open join mysql://user:[password-:-my-:-super-:-server]/my-db? "select * 
   from my-table"
or something like that I don't remember
Pekr
12-Jan-2006
[542x2]
I would expect that - why is your db query part of opening sequence?
with read, it would make sense ...
Coccinelle
12-Jan-2006
[544]
Yes perhaps, it fails also with read
Pekr
12-Jan-2006
[545]
I am of course for fixing all possible bugs, but just now simply 
everything seems to work, we are able to connect to new dbs, that 
was main point ...
Coccinelle
12-Jan-2006
[546x3]
Here is the correction of the init function :
;------ Public interface ------

    init: func [port [port!] spec /local scheme args][

;    	either args: find spec #"?" [                              
                   ; removed

;    		spec: sys-copy/part spec args                             
 ; removed

;    		fast-query: dehex sys-copy next args                   ; removed

;    	][                                                         
                                       ; removed

;    		fast-query: none                                          
              ; removed

;    	]                                                          
                                        ; removed
        if url? spec [net-utils/url-parser/parse-url port spec] 
        scheme: port/scheme 
        port/url: spec 
        if none? port/host [

            net-error reform ["No network server for" scheme "is specified"]
        ] 
        if none? port/port-id [

            net-error reform ["No port address for" scheme "is specified"]
        ]

     either all [port/target args: find port/target #"?"] [           
                   ; added

      port/target: sys-copy/part port/target args                      
       ; added

      fast-query: dehex sys-copy next args                             
       ; added

     ][                                                               
                                                 ; added

      fast-query: none                                                 
                       ; added

     ]                                                                
                                                 ; added
        if none? port/target [

      net-error reform ["No database name for" scheme "is specified"]
        ]
        if none? port/user [port/user: make string! 0]
        if none? port/pass [port/pass: make string! 0]
        if port/pass = "?" [port/pass: ask/hide "Password: "]
    ]
For the lonlong conversion, the conversion model is initialized to 
none. It should be initialized to integer like this :
	conv-model: [
		decimal			[to decimal!]
		tiny			[to integer!]
		short			[to integer!]
		long			[to integer!]
		float			[to decimal!]
		double			none
		null			none
		timestamp		none
;		longlong		none		; Removed
		longlong		[to integer!]	; Added
		int24			[to integer!]
		date			[to date!]
		time			[to time!]
		datetime		[to date!]
		year			[to integer!]
		newdate			none
		enum			none
		set				none
		tiny-blob		none
		medium-blob		none
		long-blob		none
		blob			none
		var-string		none
		string			none
	]
And the last bug is that the "byte" word is not initialized to none 
and this cause a problem but I don't remember the effect :
;------ Data reading ------


;	b0: b1: b2: b3: int: int24: long: string: field: len: none	; Removed

 b0: b1: b2: b3: int: int24: long: byte: string: field: len: none	; 
 Added
Pekr
12-Jan-2006
[549x2]
nice - so, let's wait what Doc thinks about it ....
the truth is, that I met with no problem so far using current scheme 
....