Firebird SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesFirebird SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 20th, 2006, 08:25 AM
zxcv zxcv is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Posts: 3 zxcv User rank is Lance Corporal (50 - 100 Reputation Level)zxcv User rank is Lance Corporal (50 - 100 Reputation Level)zxcv User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 54 m 30 sec
Reputation Power: 0
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?

Reply With Quote
  #2  
Old September 20th, 2006, 11:17 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,907 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 3 Days 9 h 21 m 6 sec
Reputation Power: 279
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.

Reply With Quote
  #3  
Old September 21st, 2006, 06:11 AM
zxcv zxcv is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Posts: 3 zxcv User rank is Lance Corporal (50 - 100 Reputation Level)zxcv User rank is Lance Corporal (50 - 100 Reputation Level)zxcv User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 54 m 30 sec
Reputation Power: 0
Quote:
Originally Posted by pabloj
Forced writes are enabled by default, why do you want to disable them? You risk data corruption!

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:
Originally Posted by pabloj
The config file holds this setting, you can ship your install package with a preconfigured one.

AFAIK conf file doesn't hold this (though contains two params for disabled forced writes mode), this is a DB level option.

Reply With Quote
  #4  
Old September 21st, 2006, 07:07 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,907 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 3 Days 9 h 21 m 6 sec
Reputation Power: 279
Quote:
Originally Posted by zxcv
... 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.
Do you wrap your inserts into one transaction of commit after each one? This affects insert/update speed a lot, see this thread.
Quote:
Originally Posted by zxcv
AFAIK conf file doesn't hold this (though contains two params for disabled forced writes mode), this is a DB level option.
I might be wrong on this.

Reply With Quote
  #5  
Old September 22nd, 2006, 07:58 AM
zxcv zxcv is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Posts: 3 zxcv User rank is Lance Corporal (50 - 100 Reputation Level)zxcv User rank is Lance Corporal (50 - 100 Reputation Level)zxcv User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 54 m 30 sec
Reputation Power: 0
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);
	}
Comments on this post
pabloj agrees!

Reply With Quote
  #6  
Old September 22nd, 2006, 08:54 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,907 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 3 Days 9 h 21 m 6 sec
Reputation Power: 279
Quote:
Originally Posted by zxcv
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.
Thank you very much for your contribution!!!

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesFirebird SQL Development > How do I manage Forced Writes DB option?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT