summaryrefslogtreecommitdiff
path: root/pgsql.c
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2012-04-20 11:38:51 +0200
committerAndreas Baumann <abaumann@yahoo.com>2012-04-20 11:38:51 +0200
commitdaa854033ba1ee2b3b6075bf4f1af516d0d11487 (patch)
treea33b5daa0a8843ecb7dbdf5fc9047652a07a5e16 /pgsql.c
parent7b6fc96d7710b1467420a548a7ae7b1e9b7b56fa (diff)
downloadpgfuse-daa854033ba1ee2b3b6075bf4f1af516d0d11487.tar.gz
pgfuse-daa854033ba1ee2b3b6075bf4f1af516d0d11487.tar.bz2
substr on bytea is from 1, not from 0 offset (read docu :-) )
Diffstat (limited to 'pgsql.c')
-rw-r--r--pgsql.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/pgsql.c b/pgsql.c
index 4c6f419..613cc95 100644
--- a/pgsql.c
+++ b/pgsql.c
@@ -459,7 +459,7 @@ static int psql_write_block( PGconn *conn, const int id, const char *path, const
{
int param1 = htonl( id );
int param2 = htonl( block_no );
- const char *values[3] = { (const char *)&param1, (const char *)&param2, buf + offset };
+ const char *values[3] = { (const char *)&param1, (const char *)&param2, buf };
int lengths[3] = { sizeof( param1 ), sizeof( param2 ), len };
int binary[3] = { 1, 1, 1 };
PGresult *res;
@@ -479,25 +479,25 @@ update_again:
strcpy( sql, "UPDATE data set data = $3::bytea WHERE dir_id=$1::int4 AND block_no=$2::int4" );
- /* small in the middle write, keep data on both sides */
- } else if( offset > 0 && offset + len < STANDARD_BLOCK_SIZE ) {
-
- sprintf( sql, "UPDATE data set data = substring( data from %d for %d ) || $3::bytea || substring( data from %d for %d ) WHERE dir_id=$1::int4 AND block_no=$2::int4",
- 0, (unsigned int)offset,
- (unsigned int)offset + len, STANDARD_BLOCK_SIZE - ( (unsigned int)offset + len ) );
-
/* keep data on the right */
} else if( offset == 0 && len < STANDARD_BLOCK_SIZE ) {
sprintf( sql, "UPDATE data set data = $3::bytea || substring( data from %d for %d ) WHERE dir_id=$1::int4 AND block_no=$2::int4",
- len, STANDARD_BLOCK_SIZE - len );
+ len + 1, STANDARD_BLOCK_SIZE - len );
/* keep data on the left */
} else if( offset > 0 && offset + len == STANDARD_BLOCK_SIZE ) {
sprintf( sql, "UPDATE data set data = substring( data from %d for %d ) || $3::bytea WHERE dir_id=$1::int4 AND block_no=$2::int4",
- 0, (unsigned int)offset );
-
+ 1, (unsigned int)offset );
+
+ /* small in the middle write, keep data on both sides */
+ } else if( offset > 0 && offset + len < STANDARD_BLOCK_SIZE ) {
+
+ sprintf( sql, "UPDATE data set data = substring( data from %d for %d ) || $3::bytea || substring( data from %d for %d ) WHERE dir_id=$1::int4 AND block_no=$2::int4",
+ 1, (unsigned int)offset,
+ (unsigned int)offset + len + 1, STANDARD_BLOCK_SIZE - ( (unsigned int)offset + len ) );
+
/* we should never get here */
} else {
syslog( LOG_ERR, "Unhandled write case for file '%s' in block '%d': offset: %u, len: %u, blocksize: %u",