Subject Re: Is This Database Running As Embedded Server or Client Server?
Author inoffensive_2009
--- In firebird-support@yahoogroups.com, "Martijn Tonies" <m.tonies@...> wrote:
>
> Hello Larry,
>
> >> >> > I have a backup utility that needs to run with apps using embedded
> >> >> > server or client-server versions of Firebird.
> >> >> >
> >> >> > This utility needs to know if it's running embedded, so it won't
> >> >> > run
> >> >> > svc->Shutdown().
> >> >> >
> >> >> > I don't see a column in a system table that will tell me if I'm
> >> >> > running
> >> >> > an embedded server or a client-server version of Firebird.
> >> >> >
> >> >> > How can this utility know the server type?
> >> >>
> >> >> Why do yu want to shut down the server anyway?
> >> >>
> >> >> Is it so you can safely copy the database file(s)?
> >> >>
> >> >> If so, I suggest a different approach:
> >> >> - run "gbak", or use the "Services API" of Firebird to create a
> >> >> Firebird
> >> >> backup
> >> >> - copy the resulting file
> >> >
> >> > Thanks Martijn:
> >> >
> >> > Oh CRAP!
> >> >
> >> > My typo. It's the recover utility, not the backup. Backup works
> >> > fine
> >> > with either type of server.
> >> >
> >> > Sorry.
> >> >
> >> > The app does use the services API. I want to keep the recovery as
> >> > simple for the non-technical users I expect to be running the app, and
> >> > administering the database. So the app has a "Recover" button and a
> >> > dialog asking the location of the source of the recovery.
> >> >
> >>
> >> What does the recover functionality do?
> >
> > Thanks again Martijn:
> >
> > Here is the recover function. It's C++ using IBPP.
>
> Right, well, still no clue what it does... Can you explain it? :-) What is
> it
> -supposed- to do?
>
> With regards,
>
> Martijn Tonies
> Upscene Productions
> http://www.upscene.com
>
> Download Database Workbench for Oracle, MS SQL Server, Sybase SQL
> Anywhere, MySQL, InterBase, NexusDB and Firebird!
>
> Database questions? Check the forum:
> http://www.databasedevelopmentforum.com
>
>
> > bool DATABASE_RECORD::recover_database(
> > const TCHAR *recover_database_filename,
> > HWND progress_window_handle,
> > DSM database_shutdown_mode,
> > int database_shutdown_timeout_seconds,
> > tstring *message_string_ptr)
> > {
> > bool error_found = false;
> > bool finished = false;
> > const char *wait_message_ptr = NULL;
> > DWORD file_attribute = 0;
> >
> > try
> > {
> > // The user may not have a database.
> > if(database_id != NULL)
> > {
> > disconnect();
> > }

Start the service:

> > // This is directly from oliver.
> > IBPP::Service svc =
> > IBPP::ServiceFactory(db_server_name.c_str(),
> > db_user_name,
> > db_password);

Connect the service:

> > svc->Connect();

This file attribute test is going away, it doesn't work with Firebird name aliases.

#if 0

Commenting out...
> > file_attribute = GetFileAttributes(db_path_and_name.c_str());
> >
> > if((file_attribute != INVALID_FILE_ATTRIBUTES) &&
> > ((file_attribute & FILE_ATTRIBUTE_DIRECTORY) == 0))

#endif

> > {
> > // The file exists and isn't a directory.

Shutdown the service.

> > svc->Shutdown(db_path_and_name,
> > database_shutdown_mode,
> > database_shutdown_timeout_seconds);

Start the restore

> > svc->StartRestore(string(recover_database_filename),
> > db_path_and_name, 8192,
> > IBPP::BRF(IBPP::brVerbose |
> > IBPP::brReplace |
> > IBPP::brPerTableCommit));
> >
> > finished = false;
> > *message_string_ptr = TEXT("\n");
> >
> > while(!finished)
> > {
> > wait_message_ptr = svc->WaitMsg();
> > finished = wait_message_ptr == NULL;
> >
> > if(!finished)
> > {
> > < Write messages into a progress edit box.
> > }
> > }
> > }
> >
> > // If we did shutdown, no restart is required
> > // as the DB has been restored
> > svc->Disconnect();
> > }
> >
> > catch (IBPP::Exception& e)
> > {
> > < Some catch clause stuff. >
> > }
> >
> > return !error_found;
> > }
> >
> > I posted about this a while ago, and was told that I shouldn't do the
> > svc->Shutdown() for apps using embedded Firebird.
> >
> > This recovery function has been working with apps that use either
> > embedded or client server Firebird, until tonight.
> >
> > It stopped working on one app that runs only embedded Firebird, but it
> > works on another that can use both, and works tonight on either.
> >
> > The svc->Shutdown() threw an exception.
> >
> > If I comment out the svc->Shutdown() for the app that was failing, the
> > recovery works fine.
> >
> > So I'd like to be able to test for an embedded database in the recovery
> > function.
> >
> > Thanks
> > Larry
> >
>