mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Fix bug 592719 - postgres backend aborts with date problems on transactions
Store invalid dates as NULL in the database, and when loading a NULL, that date doesn't need to be set. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18273 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
a3804f6129
commit
e724acd97b
@ -1011,6 +1011,8 @@ row_get_value_at_col_name( GncSqlRow* row, const gchar* col_name )
|
||||
GncDbiSqlRow* dbi_row = (GncDbiSqlRow*)row;
|
||||
gushort type;
|
||||
GValue* value;
|
||||
time_t time;
|
||||
struct tm tm_struct;
|
||||
|
||||
type = dbi_result_get_field_type( dbi_row->result, col_name );
|
||||
value = g_new0( GValue, 1 );
|
||||
@ -1029,8 +1031,21 @@ row_get_value_at_col_name( GncSqlRow* row, const gchar* col_name )
|
||||
(void)g_value_init( value, G_TYPE_STRING );
|
||||
g_value_take_string( value, dbi_result_get_string_copy( dbi_row->result, col_name ) );
|
||||
break;
|
||||
case DBI_TYPE_DATETIME:
|
||||
if( dbi_result_field_is_null( dbi_row->result, col_name ) ) {
|
||||
return NULL;
|
||||
} else {
|
||||
time = dbi_result_get_datetime( dbi_row->result, col_name );
|
||||
(void)gmtime_r( &time, &tm_struct );
|
||||
(void)g_value_init( value, G_TYPE_STRING );
|
||||
g_value_take_string( value,
|
||||
g_strdup_printf( "%d%02d%02d%02d%02d%02d",
|
||||
1900+tm_struct.tm_year, tm_struct.tm_mon+1, tm_struct.tm_mday,
|
||||
tm_struct.tm_hour, tm_struct.tm_min, tm_struct.tm_sec ) );
|
||||
}
|
||||
break;
|
||||
default:
|
||||
PERR( "Unknown DBI_TYPE: %d\n", type );
|
||||
PERR( "Field %s: unknown DBI_TYPE: %d\n", col_name, type );
|
||||
g_free( value );
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1687,11 +1687,7 @@ load_date( const GncSqlBackend* be, GncSqlRow* row,
|
||||
g_return_if_fail( table_row != NULL );
|
||||
|
||||
val = gnc_sql_row_get_value_at_col_name( row, table_row->col_name );
|
||||
if( val == NULL ) {
|
||||
date = g_date_new_dmy( (GDateDay)1, 1, 1970 );
|
||||
(*setter)( pObject, date );
|
||||
g_date_free( date );
|
||||
} else {
|
||||
if( val != NULL ) {
|
||||
if( G_VALUE_HOLDS_STRING( val ) ) {
|
||||
// Format of date is YYYYMMDD
|
||||
const gchar* s = g_value_get_string( val );
|
||||
@ -1706,7 +1702,8 @@ load_date( const GncSqlBackend* be, GncSqlRow* row,
|
||||
strncpy( buf, &s[4], 2 );
|
||||
buf[2] = '\0';
|
||||
month = (guint)atoi( buf );
|
||||
day = (GDateDay)atoi( &s[6] );
|
||||
strncpy( buf, &s[6], 2 );
|
||||
day = (GDateDay)atoi( buf );
|
||||
|
||||
if( year != 0 || month != 0 || day != (GDateDay)0 ) {
|
||||
date = g_date_new_dmy( day, month, year );
|
||||
@ -1753,12 +1750,14 @@ add_gvalue_date_to_slist( const GncSqlBackend* be, QofIdTypeConst obj_name,
|
||||
g_assert( value != NULL );
|
||||
getter = gnc_sql_get_getter( obj_name, table_row );
|
||||
if( getter != NULL ) {
|
||||
(void)g_value_init( value, G_TYPE_STRING );
|
||||
date = (GDate*)(*getter)( pObject, NULL );
|
||||
if( g_date_valid( date ) ) {
|
||||
buf = g_strdup_printf( "%04d%02d%02d",
|
||||
g_date_get_year( date ), g_date_get_month( date ), g_date_get_day( date ) );
|
||||
(void)g_value_init( value, G_TYPE_STRING );
|
||||
g_value_take_string( value, buf );
|
||||
}
|
||||
}
|
||||
|
||||
(*pList) = g_slist_append( (*pList), value );
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user