Permalink
Browse files

Merge pull request #3 from GswOne/patch-1

Add UTF8encode to GridFS
  • Loading branch information...
2 parents 51ffd9f + aab1376 commit 81419d1e804bdc18437ba3c7297e86ca68f11d82 @gerald-lindsly committed Jan 4, 2013
Showing with 18 additions and 13 deletions.
  1. +18 −13 GridFS.pas
View
@@ -231,8 +231,8 @@ implementation
begin
conn := mongo;
handle := gridfs_create();
- if gridfs_init(mongo.handle, PAnsiChar(AnsiString(db)),
- PAnsiChar(AnsiString(prefix)), handle) <> 0 then begin
+ if gridfs_init(mongo.handle, PAnsiChar(System.UTF8Encode(db)),
+ PAnsiChar(System.UTF8Encode(prefix)), handle) <> 0 then begin
gridfs_dispose(handle);
Raise Exception.Create('Unable to create GridFS');
end;
@@ -251,9 +251,9 @@ implementation
function TGridFS.storeFile(filename : string; remoteName : string; contentType : string) : Boolean;
begin
- Result := (gridfs_store_file(handle, PAnsiChar(AnsiString(filename)),
- PAnsiChar(AnsiString(remoteName)),
- PAnsiChar(AnsiString(contentType))) = 0);
+ Result := (gridfs_store_file(handle, PAnsiChar(System.UTF8Encode(filename)),
+ PAnsiChar(System.UTF8Encode(remoteName)),
+ PAnsiChar(System.UTF8Encode(contentType))) = 0);
end;
function TGridFS.storeFile(filename : string; remoteName : string) : Boolean;
@@ -268,13 +268,13 @@ implementation
procedure TGridFS.removeFile(remoteName : string);
begin
- gridfs_remove_filename(handle, PAnsiChar(AnsiString(remoteName)));
+ gridfs_remove_filename(handle, PAnsiChar(System.UTF8Encode(remoteName)));
end;
function TGridFS.store(p : Pointer; length : Int64; remoteName : string; contentType : string) : Boolean;
begin
- Result := (gridfs_store_buffer(handle, p, length, PAnsiChar(AnsiString(remoteName)),
- PAnsiChar(AnsiString(contentType))) = 0);
+ Result := (gridfs_store_buffer(handle, p, length, PAnsiChar(System.UTF8Encode(remoteName)),
+ PAnsiChar(System.UTF8Encode(contentType))) = 0);
end;
function TGridFS.store(p : Pointer; length : Int64; remoteName : string) : Boolean;
@@ -296,7 +296,7 @@ implementation
begin
gfs := gridfs;
handle := gridfile_create();
- gridfile_writer_init(handle, gridfs.handle, PAnsiChar(AnsiString(remoteName)), PAnsiChar(AnsiString(contentType)));
+ gridfile_writer_init(handle, gridfs.handle, PAnsiChar(System.UTF8Encode(remoteName)), PAnsiChar(System.UTF8Encode(contentType)));
end;
constructor TGridfileWriter.Create(gridfs : TGridFS; remoteName : string);
@@ -333,8 +333,7 @@ implementation
if gridfs_find_query(handle, query.handle, gf.handle) = 0 then
Result := gf
else begin
- gridfile_dispose(gf.handle);
- gf.handle := nil;
+ gf.Free;
Result := nil;
end;
end;
@@ -431,7 +430,10 @@ implementation
b := TBson.Create(bson_create());
gridfile_get_chunk(handle, i, b.handle);
if b.size() <= 5 then
- Result := nil
+ begin
+ bson_dispose(b);
+ Result := nil;
+ end
else
Result := b;
end;
@@ -443,7 +445,10 @@ implementation
cursor := TMongoCursor.Create();
cursor.handle := gridfile_get_chunks(handle, i, count);
if cursor.handle = nil then
- Result := nil
+ begin
+ cursor.free;
+ Result := nil;
+ end
else
Result := cursor;
end;

0 comments on commit 81419d1

Please sign in to comment.