Subject | Sync database metadata |
---|---|
Author | Aurimas Černius |
Post date | 2010-05-05T12:46:06Z |
Hello,
I need to sync two databases - update users database to newer version.
This task can be achieved with IBExpert, but don't want each user to buy
IBExpert, also now we are facing the problem of more complicated
database changes.
Droppping evething except tables in database was not difficult. The
problem is to create everything back, after the necessairy updates are
done. The problem is:
* IBOQuery component fails to alter one procedure (ALTER PROCEDURE
statement fails with mityrious error).
* A query component from UIB does the job, but all commented lines are
gone. This is not a desired effect, as well as we can't be sure, that
everything was successfull (IBExpert compare is how we check that).
Database structure is simply too large to check manually.
I've been trying to solve the problem by working directly with Firebird
API, but here I have some trouble: a call to isc_start_transaction()
causes Access Violation. I'm using Borland C++ Builder 6. Can anyone
point me to an error? Here's the source for a program:
//---------------------------------------------------
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "example.h"
#include <ibase.h>
char demo_view[] =
"create view demo (\n\
id\n\
) as\n\
select\n\
1\n\
from rdb$database\n\
--demo view\n\
";
void create_demo_view()
{
isc_db_handle DB = NULL;
isc_tr_handle trans = NULL;
ISC_STATUS_ARRAY status;
char dpb[256];
char *p_dpb = dpb;
short dpb_length;
*p_dpb++ = isc_dpb_version1;
*p_dpb++ = isc_dpb_user_name;
*p_dpb++ = strlen("SYSDBA");
memcpy(p_dpb, "SYSDBA", strlen("SYSDBA"));
p_dpb += strlen("SYSDBA");
*p_dpb++ = isc_dpb_password;
*p_dpb++ = strlen("masterkey");
memcpy(p_dpb, "masterkey", strlen("masterkey"));
p_dpb += strlen("masterkey");
dpb_length = p_dpb - dpb;
if(isc_attach_database(status, 0, "audi:/home/db/playdb.dat", &DB,
dpb_length, dpb))
{
char error[255];
ISC_STATUS *pstatus = status;
isc_interprete(error, &pstatus);
return;
}
if(isc_start_transaction(status, &trans, 1, &DB, 0, NULL))
return;
if(isc_dsql_execute_immediate(status, &DB, &trans, 0, demo_view, 3,
NULL))
isc_rollback_transaction(status, &trans);
else if(isc_commit_transaction(status, &trans))
isc_rollback_transaction(status, &trans);
isc_detach_database(status, &DB);
}
int main(int argc, char **argv)
{
create_demo_view();
return 0;
}
//---------------------------------------------------
Any other suggestions are welcome. Thanks.
--
Aurimas
I need to sync two databases - update users database to newer version.
This task can be achieved with IBExpert, but don't want each user to buy
IBExpert, also now we are facing the problem of more complicated
database changes.
Droppping evething except tables in database was not difficult. The
problem is to create everything back, after the necessairy updates are
done. The problem is:
* IBOQuery component fails to alter one procedure (ALTER PROCEDURE
statement fails with mityrious error).
* A query component from UIB does the job, but all commented lines are
gone. This is not a desired effect, as well as we can't be sure, that
everything was successfull (IBExpert compare is how we check that).
Database structure is simply too large to check manually.
I've been trying to solve the problem by working directly with Firebird
API, but here I have some trouble: a call to isc_start_transaction()
causes Access Violation. I'm using Borland C++ Builder 6. Can anyone
point me to an error? Here's the source for a program:
//---------------------------------------------------
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "example.h"
#include <ibase.h>
char demo_view[] =
"create view demo (\n\
id\n\
) as\n\
select\n\
1\n\
from rdb$database\n\
--demo view\n\
";
void create_demo_view()
{
isc_db_handle DB = NULL;
isc_tr_handle trans = NULL;
ISC_STATUS_ARRAY status;
char dpb[256];
char *p_dpb = dpb;
short dpb_length;
*p_dpb++ = isc_dpb_version1;
*p_dpb++ = isc_dpb_user_name;
*p_dpb++ = strlen("SYSDBA");
memcpy(p_dpb, "SYSDBA", strlen("SYSDBA"));
p_dpb += strlen("SYSDBA");
*p_dpb++ = isc_dpb_password;
*p_dpb++ = strlen("masterkey");
memcpy(p_dpb, "masterkey", strlen("masterkey"));
p_dpb += strlen("masterkey");
dpb_length = p_dpb - dpb;
if(isc_attach_database(status, 0, "audi:/home/db/playdb.dat", &DB,
dpb_length, dpb))
{
char error[255];
ISC_STATUS *pstatus = status;
isc_interprete(error, &pstatus);
return;
}
if(isc_start_transaction(status, &trans, 1, &DB, 0, NULL))
return;
if(isc_dsql_execute_immediate(status, &DB, &trans, 0, demo_view, 3,
NULL))
isc_rollback_transaction(status, &trans);
else if(isc_commit_transaction(status, &trans))
isc_rollback_transaction(status, &trans);
isc_detach_database(status, &DB);
}
int main(int argc, char **argv)
{
create_demo_view();
return 0;
}
//---------------------------------------------------
Any other suggestions are welcome. Thanks.
--
Aurimas