Skip to content

Commit ff67038

Browse files
committed
Minor fixups to dbi backend:
* dbi_conn_error_flag is deprecated, replace with dbi_conn_error (Thanks, Christian). * Switch from OS-determined HOST_NAME_MAX to locally defined GNC_HOSTNAME_MAX so that the field is always 255 regardless of what OS creates it. * Use G_OS_WIN32 instead of naked WIN32 git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@19740 57a11ea4-9604-0410-9ed3-97b8803252fd
1 parent a7c83bc commit ff67038

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/backend/dbi/gnc-backend-dbi.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,16 @@
5858
#include "splint-defs.h"
5959
#endif
6060

61-
#ifdef WIN32
61+
#ifdef G_OS_WIN32
6262
#include <Winsock2.h>
63-
#define HOST_NAME_MAX 255
6463
#define GETPID() GetCurrentProcessId()
6564
#else
6665
#include <limits.h>
6766
#include <unistd.h>
68-
#ifdef DARWIN
69-
#define HOST_NAME_MAX _POSIX_HOST_NAME_MAX
70-
#endif
7167
#define GETPID() getpid()
7268
#endif
7369

70+
#define GNC_HOST_NAME_MAX 255
7471
#define TRANSACTION_NAME "trans"
7572

7673
static QofLogModule log_module = G_LOG_DOMAIN;
@@ -333,6 +330,7 @@ gnc_dbi_sqlite3_session_begin( QofBackend *qbe, QofSession *session,
333330
result = dbi_conn_connect( be->conn );
334331
g_free( basename );
335332
g_free( dirname );
333+
/* Need some better error handling here. In particular, need to emit a QOF_ERROR_LOCKED if the database is in use by another process. */
336334
if ( result < 0 )
337335
{
338336
PERR( "Unable to connect to %s: %d\n", book_id, result );
@@ -478,8 +476,8 @@ gnc_dbi_lock_database ( QofBackend* qbe, gboolean ignore_lock )
478476
dbi_result_free( result );
479477
result = NULL;
480478
}
481-
result = dbi_conn_queryf( dcon, "CREATE TABLE GNCLOCK ( Hostname varchar(%d), PID int )", HOST_NAME_MAX );
482-
if ( dbi_conn_error_flag( dcon ) )
479+
result = dbi_conn_queryf( dcon, "CREATE TABLE GNCLOCK ( Hostname varchar(%d), PID int )", GNC_HOST_NAME_MAX );
480+
if ( dbi_conn_error( dcon, NULL ) )
483481
{
484482
const gchar *errstr;
485483
dbi_conn_error( dcon, &errstr );
@@ -503,7 +501,7 @@ gnc_dbi_lock_database ( QofBackend* qbe, gboolean ignore_lock )
503501
if ( (result = dbi_conn_query( dcon, "BEGIN" )) )
504502
{
505503
/* Check for an existing entry; delete it if ignore_lock is true, otherwise fail */
506-
gchar hostname[ HOST_NAME_MAX + 1 ];
504+
gchar hostname[ GNC_HOST_NAME_MAX + 1 ];
507505
if (result)
508506
{
509507
dbi_result_free( result );
@@ -541,7 +539,7 @@ gnc_dbi_lock_database ( QofBackend* qbe, gboolean ignore_lock )
541539
}
542540
/* Add an entry and commit the transaction */
543541
memset( hostname, 0, sizeof(hostname) );
544-
gethostname( hostname, HOST_NAME_MAX );
542+
gethostname( hostname, GNC_HOST_NAME_MAX );
545543
result = dbi_conn_queryf( dcon,
546544
"INSERT INTO GNCLOCK VALUES ('%s', '%d')",
547545
hostname, (int)GETPID() );
@@ -588,7 +586,7 @@ gnc_dbi_unlock( QofBackend *qbe )
588586
const gchar *dbname = NULL;
589587

590588
g_return_if_fail( dcon != NULL );
591-
g_return_if_fail( dbi_conn_error_flag( dcon ) == 0 );
589+
g_return_if_fail( dbi_conn_error( dcon, NULL ) == 0 );
592590

593591
dbname = dbi_conn_get_option( dcon, "dbname" );
594592
/* Check if the lock table exists */
@@ -607,14 +605,14 @@ gnc_dbi_unlock( QofBackend *qbe )
607605
if ( ( result = dbi_conn_query( dcon, "BEGIN" )) )
608606
{
609607
/* Delete the entry if it's our hostname and PID */
610-
gchar hostname[ HOST_NAME_MAX + 1 ];
608+
gchar hostname[ GNC_HOST_NAME_MAX + 1 ];
611609
if (result)
612610
{
613611
dbi_result_free( result );
614612
result = NULL;
615613
}
616614
memset( hostname, 0, sizeof(hostname) );
617-
gethostname( hostname, HOST_NAME_MAX );
615+
gethostname( hostname, GNC_HOST_NAME_MAX );
618616
result = dbi_conn_queryf( dcon, "SELECT * FROM GNCLOCK WHERE Hostname = '%s' AND PID = '%d'", hostname, (int)GETPID() );
619617
if ( result && dbi_result_get_numrows( result ) )
620618
{

0 commit comments

Comments
 (0)