|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
How do I manage Forced Writes DB option?
Hi,
(I've seen Sticky: Firebird resources thread) I need to manage Forced Writes DB option programmatically. I use FB 1.5.2 and access it with ADO through ODBC driver from native C++, so Firebird .NET data provider is not my case. BTW what is the most recent COMPLETE FB SQL syntax reference? Looks like it's an Interbase 6 one (http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_60_sqlref )? Having inspected FB sources I found that CREATE DATABASE, ALTER DATABASE statements have nothing to do with forced writes. So looks like FB client library is the only option for me, right? Did someone have an experience setting DB options with client library, or maybe one can point to an example? |
|
#2
|
||||
|
||||
|
Forced writes are enabled by default, why do you want to disable them? You risk data corruption!
The config file holds this setting, you can ship your install package with a preconfigured one.
__________________
My blog Tutorials about OSS databases, DBMonster ... Contribute to OSS Development, fill bug reports! Developer Shed eSupport Commented my.ini/my.cnf (ADD YOUR OWN CONFIG TRICK) An introduction to database normalization Natural or Surrogate key Custom ordering for your results Correlated and uncorrelated subqueries Don't turn your outer joins into inner joins Random data (with a bias) |
|
#3
|
||||
|
||||
|
Quote:
I'm aware of the risk. I need to perform kind of manual database synchronization (don't offer me to use replication). It works must faster with disabled forced writes, after that I'm gonna turn it on again. Quote:
AFAIK conf file doesn't hold this (though contains two params for disabled forced writes mode), this is a DB level option. |
|
#4
|
||||
|
||||
|
Quote:
Quote:
|
|
#5
|
|||
|
|||
|
Ok, I've done it finally. I post here code excerpt from my test MFC app, as someone else might find it useful, because the matter is poorly documented and I had to dig FB .NET data provider source code to manage. The code using FB client API can create a new FB DB with specified Forced Writes flag (BOOL m_bFW), or change the flag for existing database.
Code:
char *user = "SYSDBA", *password = "masterkey",
*service_name = "service_mgr"; // or "yourservername:service_mgr"
ISC_STATUS status[20];
isc_svc_handle *handle = NULL;
char spb_buffer[128], *spb = spb_buffer;
if (0 == m_iCreate) // create new db
{
*spb++ = isc_dpb_version1;
*spb++ = isc_dpb_dummy_packet_interval;
*spb++ = 4; // size
*spb++ = 120;
*spb++ = 10;
*spb++ = 0;
*spb++ = 0;
*spb++ = isc_dpb_user_name;
*spb++ = strlen(user);
strcpy(spb, user);
spb += strlen(user);
*spb++ = isc_dpb_password;
*spb++ = strlen(password);
strcpy(spb, password);
spb += strlen(password);
*spb++ = isc_dpb_sql_dialect;
*spb++ = sizeof(int);
*((int*)spb) = 3;
spb += sizeof(int);
*spb++ = isc_dpb_force_write;
*spb++ = sizeof(short);
*((short*)spb) = m_bFW; // 1 or 0
spb += sizeof(short);
*spb++ = isc_dpb_page_size;
*spb++ = sizeof(int);
*((int*)spb) = 8192;
spb += sizeof(int);
if (isc_create_database(status, m_sName.GetLength(), m_sName.GetBuffer(),
(void**)&handle, spb - spb_buffer, spb_buffer, 0))
{
CString s;
s.Format("Call to isc_create_database() failed with code %d", status[1]);
AfxMessageBox(s, MB_ICONERROR);
return;
}
}
else // update existing database
{
*spb++ = isc_spb_version;
*spb++ = isc_spb_current_version;
*spb++ = isc_spb_user_name;
*spb++ = strlen(user);
strcpy(spb, user);
spb += strlen(user);
*spb++ = isc_spb_password;
*spb++ = strlen(password);
strcpy(spb, password);
spb += strlen(password);
if (isc_service_attach(status, 0, service_name,
(void**)&handle, spb - spb_buffer, spb_buffer))
{
CString s;
s.Format("Call to isc_service_attach() failed with code %d", status[1]);
AfxMessageBox(s, MB_ICONERROR);
return;
}
memset(spb_buffer, 0, sizeof(spb_buffer));
spb = spb_buffer;
*spb++ = isc_action_svc_properties;
*spb++ = isc_spb_dbname;
*((short*)spb) = m_sName.GetLength();
spb += sizeof(short);
strcpy(spb, m_sName);
spb += m_sName.GetLength();
*spb++ = isc_spb_prp_write_mode;
*spb++ = m_bFW ? isc_spb_prp_wm_sync : isc_spb_prp_wm_async;
if (isc_service_start(status, (void**)&handle, NULL,
spb - spb_buffer, spb_buffer))
{
CString s;
s.Format("Call to isc_service_start() failed with code %d", status[1]);
AfxMessageBox(s, MB_ICONERROR);
isc_service_detach(status, (void**)&handle);
return;
}
isc_service_detach(status, (void**)&handle);
}
|
|
#6
|
||||
|
||||
|
Quote:
|
![]() |
| Viewing: Dev Shed Forums > Databases > Firebird SQL Development > How do I manage Forced Writes DB option? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|