This repository has been archived by the owner on Aug 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Could only connect and authorize to MySQL
- Loading branch information
Yuichiro MASUI
committed
Feb 13, 2010
0 parents
commit a266200
Showing
13 changed files
with
1,493 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2010 Yuichiro MASUI <masui@masuidrive.jp> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# node-mysql | ||
|
||
node-mysql is pure Javascript MySQL network driver for node.js | ||
|
||
|
||
|
||
# License | ||
|
||
MIT License. See LICENSE file. | ||
|
||
|
||
# Who? | ||
|
||
Code by Yuichiro MASUI a.k.a. masuidrive <masui@masuidrive.jp> | ||
|
||
Some code from tmtm's ruby-mysql. | ||
[http://github.com/tmtm/ruby-mysql](http://github.com/tmtm/ruby-mysql) | ||
|
||
SHA1 library from Takanori Ishikawa <takanori.ishikawa@gmail.com>. | ||
[http://www.metareal.org/](http://www.metareal.org/) | ||
|
||
Special thanks to Ryan Dahl (ry) for node.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
var sys = require('sys'); | ||
var events = require('events'); | ||
var Protocol = require('./mysql/protocol').Protocol; | ||
|
||
var Connection = function(hostname, username, password, dbname, port) { | ||
this.protocol = new Protocol(hostname, port); | ||
if(username) { | ||
this.protocol.authenticate(username, password, dbname); | ||
} | ||
}; | ||
|
||
Connection.prototype.query = function(sql) { | ||
var promise = new events.Promise(); | ||
var nfields = this.protocol.query_command(sql).addCallback(function(nfields) { | ||
sys.puts("nfields:"+sys.inspect(nfields)); | ||
}).addErrback(function(type, message) { | ||
// TODO | ||
}); | ||
return promise; | ||
} | ||
|
||
exports.Connection = Connection; | ||
|
||
/* | ||
node-mysql | ||
A node.js interface for MySQL | ||
Author: masuidrive <masui@masuidrive.jp> | ||
License: MIT License | ||
Copyright (c) Yuichiro MASUI | ||
# Original: | ||
# http://github.com/tmtm/ruby-mysql | ||
# Copyright (C) 2009-2010 TOMITA Masahiro | ||
# mailto:tommy@tmtm.org | ||
# License: Ruby's | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
var sha1; | ||
try { | ||
var crypto = require('crypto'); | ||
sha1 = function(message) { | ||
return (new crypto.Hash).init("sha1").update(message).digest(); | ||
} | ||
} | ||
catch(e) { | ||
var SHA1 = require('./sha1').SHA1; | ||
var i32tostr = function(i32) { | ||
var ret = ''; | ||
for (var i=0; i<4; ++i) { | ||
v = i32 & 0xff; | ||
i32 >>>= 8; | ||
ret = String.fromCharCode(v) + ret; | ||
} | ||
return ret; | ||
}; | ||
|
||
sha1 = function(message) { | ||
var digest = new SHA1(message).digest(); | ||
var ret = ""; | ||
for(var i=0; i<digest.length; ++i) { | ||
ret += i32tostr(digest[i]); | ||
} | ||
return ret; | ||
} | ||
} | ||
|
||
exports.encrypt_password = function(plain, scramble) { | ||
var stage1 = sha1(plain); | ||
var stage2 = sha1(scramble+sha1(stage1)); | ||
var result = ""; | ||
for(var i=0; i<stage1.length; ++i) { | ||
result += String.fromCharCode(stage1.charCodeAt(i) ^ stage2.charCodeAt(i)); | ||
} | ||
return(result); | ||
} | ||
|
||
/* | ||
node-mysql | ||
A node.js interface for MySQL | ||
http://github.com/masuidrive/node-mysql | ||
Copyright (c) Yuichiro MASUI <masui@masuidrive.jp> | ||
License: MIT License | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
exports.Charset = function(number, name, csname) { | ||
this.number = number; | ||
this.name = name; | ||
this.csname = csname; | ||
}; | ||
|
||
exports.Charset.by_number = function(n) { | ||
for(var i=0; i<charset.length; ++i) { | ||
if(n==charset[i][0]) | ||
return(new exports.Charset(charset[i][0], charset[i][1], charset[i][2])); | ||
} | ||
return undefined; | ||
}; | ||
|
||
exports.Charset.by_name = function(n) { | ||
for(var i=0; i<charset.length; ++i) { | ||
if(n==charset[i][2]) | ||
return(new exports.Charset(charset[i][0], charset[i][1], charset[i][2])); | ||
} | ||
return undefined; | ||
}; | ||
|
||
// [[charset_number, charset_name, collation_name, default], ...] | ||
var charset = [ | ||
[ 1, "big5", "big5_chinese_ci", true ], | ||
[ 2, "latin2", "latin2_czech_cs", false], | ||
[ 3, "dec8", "dec8_swedish_ci", true ], | ||
[ 4, "cp850", "cp850_general_ci", true ], | ||
[ 5, "latin1", "latin1_german1_ci", false], | ||
[ 6, "hp8", "hp8_english_ci", true ], | ||
[ 7, "koi8r", "koi8r_general_ci", true ], | ||
[ 8, "latin1", "latin1_swedish_ci", true ], | ||
[ 9, "latin2", "latin2_general_ci", true ], | ||
[ 10, "swe7", "swe7_swedish_ci", true ], | ||
[ 11, "ascii", "ascii_general_ci", true ], | ||
[ 12, "ujis", "ujis_japanese_ci", true ], | ||
[ 13, "sjis", "sjis_japanese_ci", true ], | ||
[ 14, "cp1251", "cp1251_bulgarian_ci", false], | ||
[ 15, "latin1", "latin1_danish_ci", false], | ||
[ 16, "hebrew", "hebrew_general_ci", true ], | ||
[ 17, "filename", "filename", true ], | ||
[ 18, "tis620", "tis620_thai_ci", true ], | ||
[ 19, "euckr", "euckr_korean_ci", true ], | ||
[ 20, "latin7", "latin7_estonian_cs", false], | ||
[ 21, "latin2", "latin2_hungarian_ci", false], | ||
[ 22, "koi8u", "koi8u_general_ci", true ], | ||
[ 23, "cp1251", "cp1251_ukrainian_ci", false], | ||
[ 24, "gb2312", "gb2312_chinese_ci", true ], | ||
[ 25, "greek", "greek_general_ci", true ], | ||
[ 26, "cp1250", "cp1250_general_ci", true ], | ||
[ 27, "latin2", "latin2_croatian_ci", false], | ||
[ 28, "gbk", "gbk_chinese_ci", true ], | ||
[ 29, "cp1257", "cp1257_lithuanian_ci", false], | ||
[ 30, "latin5", "latin5_turkish_ci", true ], | ||
[ 31, "latin1", "latin1_german2_ci", false], | ||
[ 32, "armscii8", "armscii8_general_ci", true ], | ||
[ 33, "utf8", "utf8_general_ci", true ], | ||
[ 34, "cp1250", "cp1250_czech_cs", false], | ||
[ 35, "ucs2", "ucs2_general_ci", true ], | ||
[ 36, "cp866", "cp866_general_ci", true ], | ||
[ 37, "keybcs2", "keybcs2_general_ci", true ], | ||
[ 38, "macce", "macce_general_ci", true ], | ||
[ 39, "macroman", "macroman_general_ci", true ], | ||
[ 40, "cp852", "cp852_general_ci", true ], | ||
[ 41, "latin7", "latin7_general_ci", true ], | ||
[ 42, "latin7", "latin7_general_cs", false], | ||
[ 43, "macce", "macce_bin", false], | ||
[ 44, "cp1250", "cp1250_croatian_ci", false], | ||
[ 47, "latin1", "latin1_bin", false], | ||
[ 48, "latin1", "latin1_general_ci", false], | ||
[ 49, "latin1", "latin1_general_cs", false], | ||
[ 50, "cp1251", "cp1251_bin", false], | ||
[ 51, "cp1251", "cp1251_general_ci", true ], | ||
[ 52, "cp1251", "cp1251_general_cs", false], | ||
[ 53, "macroman", "macroman_bin", false], | ||
[ 57, "cp1256", "cp1256_general_ci", true ], | ||
[ 58, "cp1257", "cp1257_bin", false], | ||
[ 59, "cp1257", "cp1257_general_ci", true ], | ||
[ 63, "binary", "binary", true ], | ||
[ 64, "armscii8", "armscii8_bin", false], | ||
[ 65, "ascii", "ascii_bin", false], | ||
[ 66, "cp1250", "cp1250_bin", false], | ||
[ 67, "cp1256", "cp1256_bin", false], | ||
[ 68, "cp866", "cp866_bin", false], | ||
[ 69, "dec8", "dec8_bin", false], | ||
[ 70, "greek", "greek_bin", false], | ||
[ 71, "hebrew", "hebrew_bin", false], | ||
[ 72, "hp8", "hp8_bin", false], | ||
[ 73, "keybcs2", "keybcs2_bin", false], | ||
[ 74, "koi8r", "koi8r_bin", false], | ||
[ 75, "koi8u", "koi8u_bin", false], | ||
[ 77, "latin2", "latin2_bin", false], | ||
[ 78, "latin5", "latin5_bin", false], | ||
[ 79, "latin7", "latin7_bin", false], | ||
[ 80, "cp850", "cp850_bin", false], | ||
[ 81, "cp852", "cp852_bin", false], | ||
[ 82, "swe7", "swe7_bin", false], | ||
[ 83, "utf8", "utf8_bin", false], | ||
[ 84, "big5", "big5_bin", false], | ||
[ 85, "euckr", "euckr_bin", false], | ||
[ 86, "gb2312", "gb2312_bin", false], | ||
[ 87, "gbk", "gbk_bin", false], | ||
[ 88, "sjis", "sjis_bin", false], | ||
[ 89, "tis620", "tis620_bin", false], | ||
[ 90, "ucs2", "ucs2_bin", false], | ||
[ 91, "ujis", "ujis_bin", false], | ||
[ 92, "geostd8", "geostd8_general_ci", true ], | ||
[ 93, "geostd8", "geostd8_bin", false], | ||
[ 94, "latin1", "latin1_spanish_ci", false], | ||
[ 95, "cp932", "cp932_japanese_ci" , true ], | ||
[ 96, "cp932", "cp932_bin" , false], | ||
[ 97, "eucjpms", "eucjpms_japanese_ci", true ], | ||
[ 98, "eucjpms", "eucjpms_bin", false], | ||
[ 99, "cp1250", "cp1250_polish_ci", false], | ||
[128, "ucs2", "ucs2_unicode_ci", false], | ||
[129, "ucs2", "ucs2_icelandic_ci", false], | ||
[130, "ucs2", "ucs2_latvian_ci", false], | ||
[131, "ucs2", "ucs2_romanian_ci", false], | ||
[132, "ucs2", "ucs2_slovenian_ci", false], | ||
[133, "ucs2", "ucs2_polish_ci", false], | ||
[134, "ucs2", "ucs2_estonian_ci", false], | ||
[135, "ucs2", "ucs2_spanish_ci", false], | ||
[136, "ucs2", "ucs2_swedish_ci", false], | ||
[137, "ucs2", "ucs2_turkish_ci", false], | ||
[138, "ucs2", "ucs2_czech_ci", false], | ||
[139, "ucs2", "ucs2_danish_ci", false], | ||
[140, "ucs2", "ucs2_lithuanian_ci", false], | ||
[141, "ucs2", "ucs2_slovak_ci", false], | ||
[142, "ucs2", "ucs2_spanish2_ci", false], | ||
[143, "ucs2", "ucs2_roman_ci", false], | ||
[144, "ucs2", "ucs2_persian_ci", false], | ||
[145, "ucs2", "ucs2_esperanto_ci", false], | ||
[146, "ucs2", "ucs2_hungarian_ci", false], | ||
[192, "utf8", "utf8_unicode_ci", false], | ||
[193, "utf8", "utf8_icelandic_ci", false], | ||
[194, "utf8", "utf8_latvian_ci", false], | ||
[195, "utf8", "utf8_romanian_ci", false], | ||
[196, "utf8", "utf8_slovenian_ci", false], | ||
[197, "utf8", "utf8_polish_ci", false], | ||
[198, "utf8", "utf8_estonian_ci", false], | ||
[199, "utf8", "utf8_spanish_ci", false], | ||
[200, "utf8", "utf8_swedish_ci", false], | ||
[201, "utf8", "utf8_turkish_ci", false], | ||
[202, "utf8", "utf8_czech_ci", false], | ||
[203, "utf8", "utf8_danish_ci", false], | ||
[204, "utf8", "utf8_lithuanian_ci", false], | ||
[205, "utf8", "utf8_slovak_ci", false], | ||
[206, "utf8", "utf8_spanish2_ci", false], | ||
[207, "utf8", "utf8_roman_ci", false], | ||
[208, "utf8", "utf8_persian_ci", false], | ||
[209, "utf8", "utf8_esperanto_ci", false], | ||
[210, "utf8", "utf8_hungarian_ci", false], | ||
[254, "utf8", "utf8_general_cs", false], | ||
]; | ||
|
||
|
||
|
||
/* | ||
node-mysql | ||
A node.js interface for MySQL | ||
http://github.com/masuidrive/node-mysql | ||
Copyright (c) Yuichiro MASUI <masui@masuidrive.jp> | ||
License: MIT License | ||
# Original: | ||
# http://github.com/tmtm/ruby-mysql | ||
# Copyright (C) 2009-2010 TOMITA Masahiro | ||
# mailto:tommy@tmtm.org | ||
# License: Ruby's | ||
*/ |
Oops, something went wrong.