forked from cory/tildefriends
		
	Fixed lots of things about storing blobs.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3680 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
		
							
								
								
									
										18
									
								
								src/ssb.db.c
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								src/ssb.db.c
									
									
									
									
									
								
							| @@ -218,10 +218,8 @@ bool tf_ssb_db_blob_store(tf_ssb_t* ssb, const uint8_t* blob, size_t size, char* | ||||
|  | ||||
| 	char id[512]; | ||||
| 	snprintf(id, sizeof(id), "&%s.sha256", hash64); | ||||
| 	printf("blob store %s\n", id); | ||||
|  | ||||
| 	const char* query = "INSERT INTO blobs (id, content, created) VALUES ($1, $2, CAST(strftime('%s') AS INTEGER)) ON CONFLICT DO NOTHING"; | ||||
| 	if (sqlite3_prepare(db, query, -1, &statement, NULL) == SQLITE_OK) | ||||
| 	if (sqlite3_prepare(db, "INSERT INTO blobs (id, content, created) VALUES ($1, $2, CAST(strftime('%s') AS INTEGER)) ON CONFLICT DO NOTHING", -1, &statement, NULL) == SQLITE_OK) | ||||
| 	{ | ||||
| 		if (sqlite3_bind_text(statement, 1, id, -1, NULL) == SQLITE_OK && | ||||
| 			sqlite3_bind_blob(statement, 2, blob, size, NULL) == SQLITE_OK) | ||||
| @@ -239,6 +237,20 @@ bool tf_ssb_db_blob_store(tf_ssb_t* ssb, const uint8_t* blob, size_t size, char* | ||||
| 		printf("prepare failed: %s\n", sqlite3_errmsg(db)); | ||||
| 	} | ||||
|  | ||||
| 	printf("blob store %s %zd => %d\n", id, size, result); | ||||
|  | ||||
| 	if (result) | ||||
| 	{ | ||||
| 		if (sqlite3_prepare(db, "DELETE FROM blob_wants WHERE id = ?1", -1, &statement, NULL) == SQLITE_OK) | ||||
| 		{ | ||||
| 			if (sqlite3_bind_text(statement, 1, id, -1, NULL) == SQLITE_OK) | ||||
| 			{ | ||||
| 				sqlite3_step(statement); | ||||
| 			} | ||||
| 			sqlite3_finalize(statement); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if (result && out_id) | ||||
| 	{ | ||||
| 		snprintf(out_id, out_id_size, "%s", id); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user