#pike __REAL_VERSION__ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
program `->Null() {return Val->Null;} |
Val.Null `->NULL() {return Val->null;} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string censor_sql_url(string sql_url) |
{ |
array(string) a = sql_url/"://"; |
string prot = a[0]; |
string host = a[1..] * "://"; |
a = host/"@"; |
if (sizeof(a) > 1) { |
host = a[-1]; |
a = (a[..<1] * "@")/":"; |
string user = a[0]; |
if (sizeof(a) > 1) { |
sql_url = prot + "://" + user + ":CENSORED@" + host; |
} |
} |
return sql_url; |
} |
|
|
class Connection |
{ |
|
inherit __builtin.Sql.Connection; |
} |
|
|
class Result |
{ |
|
inherit __builtin.Sql.Result; |
} |
|
|
class FutureResult |
{ |
|
inherit __builtin.Sql.FutureResult; |
} |
|
|
class Promise |
{ |
|
inherit __builtin.Sql.Promise; |
} |
|
protected program(Connection) find_dbm(string program_name) |
{ |
program(Connection) p; |
|
p = global.Sql[program_name]; |
if(!p && global.Sql["Provider"] && global.Sql["Provider"][program_name]) |
p = global.Sql["Provider"][program_name][program_name]; |
return p; |
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Connection Sql(string host, |
void|string|mapping(string:int|string) db, |
void|string user, void|string _password, |
void|mapping(string:int|string) options) |
{ |
|
|
string password = _password; |
_password = "CENSORED"; |
|
Connection con; |
|
if (mappingp(db)) { |
options = db; |
db = 0; |
} |
if (db == "") { |
db = 0; |
} |
if (user == "") { |
user = 0; |
} |
if (password == "") { |
password = 0; |
} |
|
string program_name; |
|
if (host && (host != replace(host, ([ ":":"", "/":"", "@":"" ]) ))) { |
|
|
|
|
|
array(string) arr = host/"://"; |
if ((sizeof(arr) > 1) && (arr[0] != "")) { |
if (sizeof(arr[0]/".pike") > 1) { |
program_name = (arr[0]/".pike")[0]; |
} else { |
program_name = arr[0]; |
} |
host = arr[1..] * "://"; |
} |
arr = host/"@"; |
if (sizeof(arr) > 1) { |
|
host = arr[-1]; |
arr = (arr[..<1]*"@")/":"; |
if (!user && sizeof(arr[0])) { |
user = arr[0]; |
} |
if (!password && (sizeof(arr) > 1)) { |
password = arr[1..]*":"; |
if (password == "") { |
password = 0; |
} |
} |
} |
arr = host/"/"; |
if (sizeof(arr) > 1) { |
host = arr[..<1]*"/"; |
if (!db) { |
db = arr[-1]; |
} |
} |
} |
|
if (host == "") { |
host = 0; |
} |
|
if (!program_name) { |
error("No protocol specified.\n"); |
} |
|
if ((sizeof(program_name / "_result") != 1) || |
((< "Sql", "sql", "sql_util", "module" >)[program_name]) ) { |
error("Unsupported protocol %O.\n", program_name); |
} |
|
program p; |
|
if (!(p = find_dbm(program_name))) { |
error("Failed to index module Sql.%s or Sql.Provider.%s.\n", |
program_name, program_name); |
} |
|
if (options) { |
con = p(host||"", db||"", user||"", password||"", options); |
} else if (password) { |
con = p(host||"", db||"", user||"", password); |
} else if (user) { |
con = p(host||"", db||"", user); |
} else if (db) { |
con = p(host||"", db); |
} else if (host) { |
con = p(host); |
} else { |
con = p(); |
} |
if (!con->query && !con->big_query) { |
con = UNDEFINED; |
error("Failed to index module Sql.%s or Sql.Provider.%s.\n", |
program_name, program_name); |
} |
|
return con; |
} |
|
#pragma no_deprecation_warnings |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
variant Connection Sql(__deprecated__(Connection) con, void|string db) |
{ |
if (db && db != "") { |
con->select_db(db); |
} |
|
return con; |
} |
|
#pragma deprecation_warnings |
|
|
|
|
|
|
|
__deprecated__(program(Result)) mysql_result = |
(__deprecated__(program(Result)))Result; |
|
|
|
|
|
|
__deprecated__(program(Result)) mysqls_result = |
(__deprecated__(program(Result)))Result; |
|
|