Launching from command line

[expired user #2297]'s profile image [expired user #2297] posted 17 years ago in General Permalink
Is it possible to start HeidiSQL from command line and pass it connection parameters from there?

I don't think there is such an option at the moment, and as far as I know no other MySQL GUI out there has that option (both open-source and commercial).
This feature is really a "must have" when servers you connect to, or their params, change often. It gets really tiresome to update connection params in multiple programs all the time so I've created a small app that enables me to keep all connection information in one XML file and use that app to launch any other program passing it appropriate parameters. This works like a charm for PuTTy and WinSCP, but I can't find a MySQL GUI that will accept connection parameters on command line.

If this feature is not available in HeidiSQL right now, does it sound like feature worth implementing in foreseeable future?

Thanks for HeidiSQL! I've been using MySQL-Front since early 2.X days and always found any other tool to be lacking some features or just too weird to use. I guess it just gets under your skin. :D
ansgar's profile image ansgar posted 17 years ago Permalink
Oh that sounds easy to implement. Just look for given parameters on startup (and connect automatically instead of waiting for the user to click "Connect"?)

Just let us gather needed parameters here:
- host
- user
- pass
- port
- maybe a database name to use?

So it could look like
heidisql.exe -hLocalhost -uUser -pPassword -db


We could even simulate the mysql-cli's behaviour which is quite good:
either
- use a given password from "-p" and connect immediately
- if an empty password given, ask for it and don't connect immediately
- if no -p parameter given, assume we have to connect with an empty password

How does that sound?
[expired user #2297]'s profile image [expired user #2297] posted 17 years ago Permalink

Oh that sounds easy to implement. Just look for given parameters on startup (and connect automatically instead of waiting for the user to click "Connect"?)


Exactly that.

Just let us gather needed parameters here:
- host
- user
- pass
- port
- maybe a database name to use?


I would definitely find db name useful, plus I think there should be an optional description parameter so if there are multiple instances of Heidi open, you can easily find the right one in task bar. This description should behave exactly the same as "Description:" in connection dialog.

So it could look like

heidisql.exe -hLocalhost -uUser -pPassword -db


We could even simulate the mysql-cli's behaviour which is quite good:
either
- use a given password from "-p" and connect immediately
- if an empty password given, ask for it and don't connect immediately
- if no -p parameter given, assume we have to connect with an empty password

How does that sound?


Puts a big smile on my face. :D
[expired user #2297]'s profile image [expired user #2297] posted 17 years ago Permalink
anse,

is this feature by any chance already implemented in svn trunk?
If so, is there a nightly build or something like that since I don't have Delphi to build it my self.

Thanks
ansgar's profile image ansgar posted 17 years ago Permalink
Sorry, not yet implemented and no nightly builds yet.

But: I started to implement that a few weeks ago and then stopped it for the benefit of other implementations. Maybe the code I wrote is useful and helps me implementing it soon.

And: I'm on the way to create a workflow for compiling nightly builds. Will need some more days or maybe 2 weeks.
[expired user #2297]'s profile image [expired user #2297] posted 17 years ago Permalink
Thanks for the update. I hope you'll get to it soon. happy

Once you implement it, perhaps you can update this post with a link to build that includes this feature so we (community) can test it right away.

Thanks
ansgar's profile image ansgar posted 17 years ago Permalink
I'm currently working on a batch file for the process of creating nightly builds. The compiler dcc32.exe needs about one million options and I'm having problems with one of them. I can't get it to "Build all units" (-B), although I switched that on:

...
-B
-I"components\zeosdbo\src\core"
...


Won't create the .DCU files here as expected. :cry:

Anyone with hints for me?
[expired user #2297]'s profile image [expired user #2297] posted 17 years ago Permalink
Visual Studio 2005 will generate BuildLog.htm for C++ projects. That file includes the commands that IDE used to build your project. Does Delphi has such an options? If so, you can probably deduce from that what IDE is doing differently.

Perhaps the order of options is important? Did you try to specify include directives first?
Maybe you should just post you whole batch file here in hopes that someone will catch some sneaky little error in it.

Sorry, can't help you more with this issue.
ansgar's profile image ansgar posted 17 years ago Permalink
I just read that Delphi 2007 has some support for msbuild which means you can build a project by just giving the projectgroup-file. msbuild then should generate a commandline for dcc32.exe. Not sure how to get it working on the commandline, but I'll look for it.

Is msbuild something I have to download seperately?
[expired user #2297]'s profile image [expired user #2297] posted 17 years ago Permalink
If you have .NET 2 installed, I believe you should already have it installed in C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 folder or something like that. If not, perhaps you only have .NET 2 runtime in which case you'll need to install .NET 2 SDK.
[expired user #484]'s profile image [expired user #484] posted 17 years ago Permalink

Just let us gather needed parameters here:
- host
- user
- pass
- port
- maybe a database name to use?



- host
- user
- pass
- port
- maybe a database name to use?
- batchscript_to_execute.sql
ansgar's profile image ansgar posted 17 years ago Permalink

... you should already have it installed in C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 folder or something like that.



Yep, found it in exactly that directory.

Seems easy:
\windows\Microsoft.NET\Framework\v2.0.50727\msbuild superpackages\delphi11\heidisql.groupproj
ansgar's profile image ansgar posted 17 years ago Permalink
See here for latest builds:
http://download.heidisql.com/
[expired user #2297]'s profile image [expired user #2297] posted 17 years ago Permalink
Wow, great news anse.

Now I just need to wait for command line thingy to be implementedhappy
Or shall I say I'll keep an eye on a FishEye 8)

Thanks!
ansgar's profile image ansgar posted 17 years ago Permalink
Fisheye has RSS feeds btw. For example checkout this one:
http://fisheye3.cenqua.com/changelog/~rss/heidisql/trunk/rss.xml
[expired user #2297]'s profile image [expired user #2297] posted 17 years ago Permalink
Yeah, I subscribed to that when I wrote my previous post. Thanks for pointing it out anyway, though.
[expired user #2297]'s profile image [expired user #2297] posted 16 years ago Permalink
I just upgraded from 3.0 to 3.2 and AFAICT, there is no support for command line parameters yet? :(
Just wanted to confirm that and ask if this is still planned for implementation some time soon?

btw. Nice work on 3.2, keep it coming.

Thanks
ansgar's profile image ansgar posted 16 years ago Permalink
A command line parser is a complex thing, not implemented in some hours. In addition my old code is unusable for that as I recently found out. Had some logical errors, so I need some new ideas for implementation.

Maybe you can help out with that feature?
[expired user #2297]'s profile image [expired user #2297] posted 16 years ago Permalink

Maybe you can help out with that feature?


I sure can try. I'm not a Delphi programmer, but if you think I can help you in some other way please let me know.

This is a long shot, but if there is some free or trial version of Delphi that I can use to build Delphi programs myself maybe I can try implementing command line parser by itself and if successful hand it over to you to integrate it into Heidi. Do you know of any such download?

I still think that copying mysql.exe behaviour for relevant command line parameters and adding --session="session name" option would be a good solution.
[expired user #2297]'s profile image [expired user #2297] posted 16 years ago Permalink
To answer my own question. There is a Delphi Turbo Explorer availabe for free here. And there is also a 30 day trial for Delphi 2007 and 2006 in case this Turbo doesn't work out for some reason.

I will download the Turbo version and see if I can find my way around it.
ansgar's profile image ansgar posted 16 years ago Permalink
Any help is very appreciated!

However, I think the Turbo versions don't support installing 3rd party components of which we have some in HeidiSQL. So, I'd recomment installing a 30 day trial of Delphi 2007.
[expired user #2297]'s profile image [expired user #2297] posted 16 years ago Permalink
I installed Delphi 2007 Trial but it doesn't seem to work as advertised. They claim on the download page that it is a "fully functional" 30 day trial version, but command line tools are not supported in trial version. That is the message you get when you try to use them.
I then tried to install the components manually, but that didn't work either. Even their demos that use third party components, like Indy, don't work because of components not installing. So I'm under the impression that free trial version also doesn't support installation of third party components, but I can't find any info on that. All in all, such a bad experience with Borland/CodeGear so far. Not to mention that documentation alone took well over an hour to install.

I am able to work on the command line parser with this trial version, so I'll see if I can get anywhere with it. I remember that I saw some free e-book on Pascal some time ago, but I can't google it now. Do you know of any free Pascal/Delphi language reference available online? Only RadStudio and VCL reference come with RadStudio 2007, but I could also use some language reference.

Off-topic: I'm not receiving notification emails for new post to topics that I am subscribed to. Are you aware of any problems with forum not mailing out notification emails?
ansgar's profile image ansgar posted 16 years ago Permalink
Oh that's too bad with the trial. However, you don't need to install the whole HeidiSQL packages to work on that parser. You could create a small command line application and make it fill some variables like sessionname, host, user, password etc. In the end some other can integrate that snippet into HeidiSQL's childwin or whatever.

And thanks a lot for the info about not receiving mails! It seems the mailserver doesn't do its job since we moved the website to our own virtual private server system.
[expired user #2297]'s profile image [expired user #2297] posted 16 years ago Permalink
To answer my own question again, I found some decent Delphi language/library reference here.

I now have some code that can parse long parameters, see below for examples. Since ParamStr() returns AnsiString values, I used AnsiStr functions throughout. Is that going to be a problem in some situations?

This is parsed correctly:
heidisql.exe --user=root --host=192.168.1.1 --password --session="My session name"
Values are returned as expected, except for password in which case we know that --password is present but its value is set to empty string.

But none of these will be parsed correctly at the moment:
heidisql.exe --user root --host 192.168.1.1 --password --session "My session name"
heidisql.exe -uroot -h192.168.1.1 -p -s"My session name"
heidisql.exe -u root -h 192.168.1.1 -p -s "My session name"
First one is, I think, not really accepted by mysql.exe either?
Second one could probably be made to work with not too much effort, if need be.
But last one would require some substantial changes, though still doable if really required.
That is what I wanted to discuss, what formats exactly are we looking to support? Long options as they work now in my first example above are good enough for me, but I'd like to hear what others think.

If I manage to compile Heidi, what would be the best place for this code/logic? Where in childwin, OnCreate? Or some other place?
ansgar's profile image ansgar posted 16 years ago Permalink
This is awesome and really helpful!

Regarding your question where to put that code: I think that's a quite complex thing. Normally Tconnform initializes the mysql connection and creates a TMDIChild. In this case we don't need Tconnform, so TMainform.FormShow should do the connect instead of passing all responsibility to TMainform.ShowConnections() + Tconnform.ButtonConnectClick(). I think we should move some code from Tconnform.ButtonConnectClick() to main.pas, call that from both places (command line passed parameters AND Tconnform.ButtonConnectClick() ).

However, once it's ready I think you should send the code snippet to heidisql-devel ...at... lists.sourceforge.net so I can discuss that with the other developers.
[expired user #2297]'s profile image [expired user #2297] posted 16 years ago Permalink

In this case we don't need Tconnform, so TMainform.FormShow should do the connect instead of passing all responsibility to TMainform.ShowConnections() + Tconnform.ButtonConnectClick(). I think we should move some code from Tconnform.ButtonConnectClick() to main.pas, call that from both places (command line passed parameters AND Tconnform.ButtonConnectClick() ).

Yes, connection logic should be moved to main.pas somewhere and act upon passed parameters, regardless of where they're coming from.

In case of --password or -p user will need to be prompted for a password. This will probably be better done from where ever the startup params are parsed and before the connect function is called.
Preferably that prompt will be a very simple modal dialog with a label like "Enter password for user@host", a password box below and OK Cancel buttons on the bottom.

I'll be mailing the code to devel list right away.

btw. I just received 4 notification emails, so it seems your mail server is working now.
ansgar's profile image ansgar posted 16 years ago Permalink

btw. I just received 4 notification emails, so it seems your mail server is working now.



Hehe. Exactlysmilethe mailserver was not configured properly yet since we moved to another machine.
ansgar's profile image ansgar posted 16 years ago Permalink
Thanks a lot for the code snippet! That will be very helpful and even looks like clean and well designed code. happy Only the CRLF constant already lives in const.inc but that's a minor thing.

However, I'll start to get it in asap. I'm working on replacing the two datagrids by TNT components, but that's nearly ready, so just gimme a week or so.
[expired user #2297]'s profile image [expired user #2297] posted 16 years ago Permalink

Only the CRLF constant already lives in const.inc but that's a minor thing.


I've only put that in so I can print the results of parsing, plus I did that as a standalone project so I didn't have access to heidisql files. But that won't be needed in heidi anyway, since heidi will not just print those to some message boxhappy

However, I'll start to get it in asap. I'm working on replacing the two datagrids by TNT components, but that's nearly ready, so just gimme a week or so.


Great! I'm looking forward to it.
If you remember, please update this post once that code is available in nightly build.
ansgar's profile image ansgar posted 16 years ago Permalink
Done in revision 1155.

Download nightly build here in 20 minutes.

A big, big thanks goes to Nemanja! happyhappy 8)
ansgar's profile image ansgar posted 16 years ago Permalink
Btw, the wrapper function MyParam was not really needed and I dropped it. You got this error "Missing operator or semicolon" because there was a variable paramStr which conflicts with a function of the same name. I just renamed the variable and it worked.
[expired user #2297]'s profile image [expired user #2297] posted 16 years ago Permalink

Btw, the wrapper function MyParam was not really needed and I dropped it. You got this error "Missing operator or semicolon" because there was a variable paramStr which conflicts with a function of the same name. I just renamed the variable and it worked.


OK, great. I couldn't really figure out what the error was about, so I put it in a wrapper function and the worked, so...
Even though I should have noticed that, I wouldn't really call the error message "descriptive". :)
[expired user #2297]'s profile image [expired user #2297] posted 16 years ago Permalink

Done in revision 1155.

Download nightly build here in 20 minutes.


Ansgar,

thank you very much for this one. And Heidi in general, of course. :D
I just did a quick test, and it seems to work perfectly. Thanks so much!

I think you should "advertise" this feature of Heidi a bit more since, as far as I know, this is the only MySQL GUI tool that has this capability. On any platform, not just windows. Again, this is only AFAIK. Though I did do fair bit of research on the subject. By "advertise", I mean something like mention it in a feature list and README, etc.

btw. I never told you how awesome your nightly builds system is. I really like how you put it together like a generally useful AND usable service, instead of just a dump of latest code in executable form. Great work on that as well!
[expired user #8716]'s profile image [expired user #8716] posted 5 years ago Permalink

what should be command to connect to two specific databases with empty password?

host: localhost
user: root
pass:
databases: db1, db2

Thanks in advance for help :)

ansgar's profile image ansgar posted 5 years ago Permalink

You connect to a server, then select a database. And you cannot select two databases at one time. Just like you cannot click on two buttons with one mouse.

For an overview of command line parameters, see the help document.

[expired user #8716]'s profile image [expired user #8716] posted 5 years ago Permalink

It doesn't even connect to single database, but I am talking about this http://prntscr.com/lob9hc I understand heidisql.exe -d=sessionname works for my case but it will more perfect If I could be able to connect using user,pass,host,dbs in cli

however thank you for your quick response :)

ansgar's profile image ansgar posted 5 years ago Permalink

Ah ok, in that case I'm afraid there is no command line switch to limit the database names you want to see.

There are just too many options in the session manager to make them all available on the command line, and most of them are never important for most users. Also, keep in mind that HeidiSQL is a GUI.

As a workaround, you could create the relevant session key by yourself, under \\HKEY_CURRENT_USER\Software\HeidiSQL\Servers, and after that use the -d=sessionname parameter on the command line.

[expired user #8716]'s profile image [expired user #8716] posted 5 years ago Permalink

I tried this http://prntscr.com/lofhki but its not appear in heidisql session manager and also can't connect via -d=sessionname ...

when I make session from heidisql gui, I can connect via -d=sessionname in cli

HERE is my real problem

Please see this screenshot http://prntscr.com/lofj7w ... it seems like -d=sessionname args need somewhere in global scope etc. Any help will be appreciated :)

ansgar's profile image ansgar posted 5 years ago Permalink

-d=mysession works as expected here.

Please test via cmd.exe box.

[expired user #8716]'s profile image [expired user #8716] posted 5 years ago Permalink

that is working in cmd, not sure why not working for my tool, here is documentation https://atom.io/docs/api/v1.11.2/BufferedProcess , all other are working fine, only heidisql command with args is not working there.

[expired user #8716]'s profile image [expired user #8716] posted 5 years ago Permalink

Please note, heidisql.exe -d=sessionname opening that sessionname from cmd but from my tool its opening first gui to login to db, default screen, it only have problem with arg -d=sessionname. any idea

[expired user #8716]'s profile image [expired user #8716] posted 5 years ago Permalink

ok, no worries, I solve it by creating a bat file in heidisql directory, here content of bat file if its helpful to someone else as well

set sessionname=%1
heidisql.exe -d=%sessionname%

Please login to leave a reply, or register at first.