mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2026-03-13 09:24:25 +08:00
get rid of duplicate db connection script and make work for oracle
This commit is contained in:
@@ -120,12 +120,14 @@ else if ("Save" == event || "Save/Connect" == event || "Connect" == event)
|
||||
if ( event.endsWith("Connect"))
|
||||
{
|
||||
HashObject profile = (HashObject)profiles.getObject(connProfiles.getText());
|
||||
String curVendor = dialog.getProperty("currentVendor");
|
||||
|
||||
args().put("profile", profile);
|
||||
DB db = (DB)script("testConnect", args());
|
||||
DB db = script(String.format("testConnect$%s", curVendor), args());
|
||||
if (db != null)
|
||||
{
|
||||
dialog.dispose();
|
||||
args().put("db", db);
|
||||
script("showMainWindow", args());
|
||||
}
|
||||
}
|
||||
@@ -200,7 +202,7 @@ else if ("Vendor" == event)
|
||||
else if ( newVendor == "oracle" )
|
||||
{
|
||||
dialog.setTitle("New Connection - Oracle");
|
||||
hostLabel.setText("Service@Host");
|
||||
hostLabel.setText("Service@Host:");
|
||||
compressBox.setEnabled(false);
|
||||
dbsLabel.setText(dbsLabel.getText().replaceAll("Database", "Schema"));
|
||||
sortBox.setText(sortBox.getText().replaceAll("database", "schema"));
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
import com.mysql.jdbc.jdbc2.optional.*;
|
||||
import javax.sql.DataSource;
|
||||
import com.rendion.editor.*;
|
||||
|
||||
DB db = null;
|
||||
|
||||
WindowContext context = argObj("windowContext");
|
||||
HashObject profile = context.get("profile");
|
||||
AjlEditor editor = context.get("/consoleTabs/SQL Log/outputWindow");
|
||||
|
||||
try
|
||||
{
|
||||
MysqlDataSource ds = new MysqlDataSource();
|
||||
String url = "jdbc:mysql://" + profile.get("host") + ":" + profile.get("port") + "/";
|
||||
|
||||
url+="?zeroDateTimeBehavior=convertToNull&useOldAliasMetadataBehavior=true";
|
||||
|
||||
if ( "true".equals(profile.get("compress")) )
|
||||
{
|
||||
url+="&useCompression=true";
|
||||
}
|
||||
ds.setUrl(url);
|
||||
ds.setUser(profile.get("user"));
|
||||
ds.setPassword(profile.get("password"));
|
||||
ds.setLoginTimeout(Integer.parseInt(profile.get("timeout")));
|
||||
|
||||
db = new SQLLoggingDB((DataSource)ds, editor);
|
||||
db.useCache(true);
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
context.put("db", db);
|
||||
|
||||
Binary file not shown.
@@ -129,9 +129,13 @@
|
||||
|
||||
app.maximize();
|
||||
app.visible();
|
||||
|
||||
DB conn = argObj("db");
|
||||
DB db = new SQLLoggingDB(conn, editor);
|
||||
db.useCache(true);
|
||||
context.put("db", db);
|
||||
|
||||
args().put("windowContext", context);
|
||||
script("initDB", args());
|
||||
Worker w = worker("initTreeWorker", args());
|
||||
LongRunningTask.detect("initTreeWorker", "progressWaiter", args(), w , 250);
|
||||
w = worker("loadHostInfoWorker", args());
|
||||
|
||||
44
extra/jheidi/testConnect$mysql.ajl
Normal file
44
extra/jheidi/testConnect$mysql.ajl
Normal file
@@ -0,0 +1,44 @@
|
||||
import com.mysql.jdbc.jdbc2.optional.*;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
DB db = null;
|
||||
|
||||
WindowContext context = argObj("windowContext");
|
||||
Frame f = context.get("/");
|
||||
HashObject profile = argObj("profile");
|
||||
|
||||
try
|
||||
{
|
||||
MysqlDataSource ds = new MysqlDataSource();
|
||||
String url = String.format("jdbc:mysql://%s:%s/?zeroDateTimeBehavior=convertToNull&useOldAliasMetadataBehavior=true&useCompression=%s",
|
||||
profile.get("host"), profile.get("port"), profile.get("compress"));
|
||||
|
||||
ds.setUrl(url);
|
||||
ds.setUser(profile.get("user"));
|
||||
ds.setPassword(profile.get("password"));
|
||||
ds.setLoginTimeout(Integer.parseInt(profile.get("timeout")));
|
||||
|
||||
db = new DB((DataSource)ds);
|
||||
db.execute("select 'abcdefg'");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Throwable cause = e.getCause();
|
||||
String message = cause.getMessage();
|
||||
|
||||
if (message.indexOf("\n") != -1)
|
||||
{
|
||||
int startMessage = message.indexOf("MESSAGE:");
|
||||
if ( startMessage != -1)
|
||||
{
|
||||
startMessage+=8;
|
||||
message = message.substring(startMessage, message.indexOf("\n", startMessage));
|
||||
}
|
||||
}
|
||||
|
||||
f.popupMessage("Connection Failed!", message);
|
||||
db = null;
|
||||
}
|
||||
|
||||
return db;
|
||||
|
||||
39
extra/jheidi/testConnect$oracle.ajl
Normal file
39
extra/jheidi/testConnect$oracle.ajl
Normal file
@@ -0,0 +1,39 @@
|
||||
import oracle.jdbc.pool.OracleDataSource;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
DB db = null;
|
||||
|
||||
WindowContext context = argObj("windowContext");
|
||||
Frame f = context.get("/");
|
||||
HashObject profile = argObj("profile");
|
||||
|
||||
try
|
||||
{
|
||||
OracleDataSource ds = new OracleDataSource();
|
||||
String host = profile.get("host");
|
||||
if ( !host.contains("@"))
|
||||
{
|
||||
host+="@localhost";
|
||||
}
|
||||
String[] serviceHost = host.split("@");
|
||||
String url = String.format("jdbc:oracle:thin:@%s:%s:%s", serviceHost[1], profile.get("port"), serviceHost[0]);
|
||||
|
||||
ds.setURL(url);
|
||||
ds.setUser(profile.get("user"));
|
||||
ds.setPassword(profile.get("password"));
|
||||
ds.setLoginTimeout(Integer.parseInt(profile.get("timeout")));
|
||||
|
||||
db = new DB((DataSource)ds);
|
||||
db.execute("select 'abcdefg' from dual");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Throwable cause = e.getCause();
|
||||
String message = cause.getMessage();
|
||||
|
||||
f.popupMessage("Connection Failed!", message);
|
||||
db = null;
|
||||
}
|
||||
|
||||
return db;
|
||||
|
||||
Reference in New Issue
Block a user