You are not logged in.
Pages: 1
i retrieve blob data from database using TSQLDBStatement,but the Query.TotalRowsRetrieved is always zero:
var
OleDBConnectionProperties:TOleDBConnectionProperties;
SQLDBConnection:TSQLDBConnection;
Query: TSQLDBStatement;
......
OleDBConnectionProperties := TOleDBConnectionProperties.Create('','','','');
OleDBConnectionProperties.ConnectionString := myrdbmstr;
try
SQLDBConnection := OleDBConnectionProperties.NewConnection;
except
OleDBConnectionProperties.Free;
exit;
end;
try
Query := SQLDBConnection.NewStatement;
except
SQLDBConnection.Disconnect;
SQLDBConnection.Free;
OleDBConnectionProperties.Free;
exit;
end;
try
Query.Execute('select blobfield from mytable where id=100',true);
aParams.Resp := Query.ColumnBlob(0);
except
Query.Free;
SQLDBConnection.Disconnect;
SQLDBConnection.Free;
OleDBConnectionProperties.Free;
aParams.Resp := '';
exit;
end;
Offline
i add step(true) or step(false) before "aParams.Resp := Query.ColumnBlob(0);",it is just the same problem.
i think 'select blobfield from mytable where id=100' makes the mistake,but it is really a correct SQL statement.
Offline
Offline
if Query.Step then
aParams.Resp := Query.ColumnBlob(0)
else
// no rows return
i check that Query.Step returns false.
but,'select blobfield from mytable where id=100' does return one row, and "blobfield" is text type of Mysql.
Offline
yes, it is a TEXT column,i use Query.ColumnUTF8(), and i also got nothing.
IMHO,Query.Execute('select blobfield from mytable where id=100',true) returns empty,
but 'select blobfield from mytable where id=100' does return one row.
Offline
You should better use
Query := OleDBConnectionProperties.Execute('select blobfield from mytable where id=100',[]);
or
Query := OleDBConnectionProperties.Execute('select blobfield from mytable where id=?,[100]);
Offline
it does not work,and also returns nothing.
the OleDB Provider i use is:mysql-connector-odbc-5.1.11-win32.msi.
Offline
ado and syndbexplorer are the same,
i try syndbexplorer ,if i use "select * from mytable where id = 100",it returns one row with the blobfield empty. if i use 'select blobfield from mytable where id=100',it makes a mistake and popup a error window. the error window just like this:
Error
OLEDB Error 80040E21 - ?? OLE DB
???????????,????? OLEDB ????????????
Exception class:EOleDBException
Offline
i use HeidiSQL 5.0.0.3272 and execute 'select blobfield from mytable where id=100',it can return one row with blobfield content,no error displays.
Offline
AFAIK HeidiSQL does not use any OleDB provider, but has direct access to the MySQL client library.
That is why I asked about direct ADO access (via your OleDB provider), and also to try with our SynDBExplorer.
The 80040E21 exception is about an unhandled feature of the used OleDB provider.
It sounds like a known limitation of the provider used. See http://www.mysqltalk.org/image-vp435971.html
In order to fix your problem, you'd have to try another OleDB provider (one non using ODBC, but direct MySQL access), like http://cherrycitysoftware.com/ccs/provi … MySQL.aspx or others.
A direct ODBC connection could be a better solution.
The unit is not yet finished. See http://synopse.info/fossil/finfo?name=SynDBODBC.pas
Offline
thanks,
perhaps i should use zeoslib at the server side as i used to.
Offline
how long shall the SynDBODBC.pas be finished? is it sutable for my case?
i really want use less third commponent.
thanks again.
Offline
i use sqlite3 and mysql at the same time.
and i used synpdf before,but it can not process chinese font from my emf file,so i pause now, and i shall pick up it later.
i post here before: http://synopse.info/forum/viewtopic.php?id=42
Offline
Direct link to MySQL could make even better sense that the ODBC link.
But I have no MySQL installation at hand, and no need nor time to do it in the close future.
Any contribution is welcome!
About SynPDF, handling font fallback is far from trivial...
Could better be fixed by setting a font explicitly having all chinese glyphs.
Offline
while using ZeosLib,another question is about json:
how to translate between ZeosLib's Query and json?
Offline
here is my code refer syndb,
unit uzjsonquery;
interface
uses Classes,SysUtils, db,ZConnection,ZSqlProcessor,ZDataset,
SQLite3, SynCommons,syndb,synoledb,SQLite3Commons;
type
TZJsonQuery = class(TZQuery)
private
protected
procedure ColumnsToJSON(WR: TJSONWriter);
function FetchAllToJSON(JSON: TStream; Expanded: boolean): PtrInt;
public
function FetchAllAsJSON(Expanded: boolean; ReturnedRowCount: PPtrInt=nil): RawUTF8;
end;
implementation
procedure TZJsonQuery.ColumnsToJSON(WR: TJSONWriter);
var col: integer;
blob: RawByteString;
tmpstream:TMemoryStream;
begin
if WR.Expand then WR.Add('{');
for col := 0 to FieldCount - 1 do begin
if WR.Expand then
WR.AddFieldName(Fields[col].FieldName); // add '"ColumnName":'
if Fields[col].IsNull then
WR.AddShort('null') else
case Fields[col].DataType of
db.ftUnknown: WR.AddShort('null');
ftSmallint, ftInteger, ftWord,ftLargeint: WR.Add(Fields[col].AsInteger);
ftFloat:WR.Add(Fields[col].AsFloat);
db.ftCurrency: WR.AddCurr64(Fields[col].AsCurrency);
db.ftDate, db.ftTime, db.ftDateTime: begin
WR.Add('"');
WR.AddDateTime(Fields[col].AsDateTime);
WR.Add('"');
end;
ftMemo,ftstring,ftWideString: begin
WR.Add('"');
WR.AddJSONEscape(pointer(Fields[col].AsString));
WR.Add('"');
end;
db.ftBlob: begin
tmpstream := TMemoryStream.Create;
try
TBlobField(Fields[col]).SaveToStream(tmpstream);
tmpstream.Position := 0;
WR.WrBase64(tmpstream.Memory,tmpstream.Size,true);
finally
tmpstream.Free;
tmpstream := nil;
end;
end;
else raise ESQLDBException.CreateFmt('%s: Invalid ColumnType() %s',
[ClassName,'']);
end;
WR.Add(',');
end;
WR.CancelLastComma; // cancel last ','
if WR.Expand then WR.Add('}');
end;
function TZJsonQuery.FetchAllToJSON(JSON: TStream; Expanded: boolean): PtrInt;
var W: TJSONWriter;
col: integer;
begin
result := 0;
W := TJSONWriter.Create(JSON,Expanded,false);
try
SetLength(W.ColNames,FieldCount);//columncount
for col := 0 to FieldCount-1 do
W.ColNames[col] := FieldDefList.FieldDefs[col].Name;
W.AddColumns;
if Expanded then W.Add('[');
First;
while (not Eof) do
begin
ColumnsToJSON(W);
W.Add(',');
inc(result);
Next;
end;
W.CancelLastComma; // cancel last ','
W.Add(']');
if not Expanded then W.Add('}');
W.Add(#10);
W.Flush;
finally
W.Free;
end;
end;
function TZJsonQuery.FetchAllAsJSON(Expanded: boolean;
ReturnedRowCount: PPtrInt=nil): RawUTF8;
var Stream: TRawByteStringStream;
RowCount: PtrInt;
begin
Stream := TRawByteStringStream.Create;
try
RowCount := FetchAllToJSON(Stream,Expanded);
if ReturnedRowCount<>nil then ReturnedRowCount^ := RowCount;
result := Stream.DataString;
finally
Stream.Free;
end;
end;
it is ok for me, and i hope it is usful for someone else.
Offline
The whole idea is good.
Thanks for sharing the code!
I suspect you'll have issues with UTF-8 encoding. You are mixing RawUTF8/UTF-8 buffers and plain String type.
Accents will probably be lost in the process.
Offline
i see, and i will check it.
thanks a lot.
Offline
u are the greatest.
Offline
Offline
Pages: 1