Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sqlite 从流中设置SQL查询参数值的正确Delphi语法是什么?_Sqlite_Delphi_Filestream - Fatal编程技术网

Sqlite 从流中设置SQL查询参数值的正确Delphi语法是什么?

Sqlite 从流中设置SQL查询参数值的正确Delphi语法是什么?,sqlite,delphi,filestream,Sqlite,Delphi,Filestream,我使用了一个需要登录的网站,并且在某一点上显示了一个使用http的jpg <img src="https://www.theurl.com/pictures/Photo.ashx?theid=221"> 我还可以使用以下命令将图像从网站下载到文件中(在运行处理登录的代码后) 不过,我不希望将每个文件都保存在客户机硬盘上,然后将其读回以保存到数据库中,因为这样会非常慢 问题 将上述两个过程结合在一起的正确语法是什么,以便我可以下载到流中,然后将流直接传递到查询参数中,以便将其保存在数

我使用了一个需要登录的网站,并且在某一点上显示了一个使用http的jpg

<img src="https://www.theurl.com/pictures/Photo.ashx?theid=221">
我还可以使用以下命令将图像从网站下载到文件中(在运行处理登录的代码后)

不过,我不希望将每个文件都保存在客户机硬盘上,然后将其读回以保存到数据库中,因为这样会非常慢

问题

将上述两个过程结合在一起的正确语法是什么,以便我可以下载到流中,然后将流直接传递到查询参数中,以便将其保存在数据库中


注意:我使用的是DISQLIte3,但查询方法/属性与其他组件类似

大多数具有LoadFromFile的类也具有LoadFromStream。你试过了吗


@Joe Meyer-是的,我看到了链接,它与数据库没有任何关系。像我在过去两天看到的大多数事情一样,它只处理进出图像的斑点

@bummi&HeartWare 我尝试了大量不同的。。。ParamByName('photo')。LoadFromStream()。。。使用Tfilestream和TmemoryStream,但不断出现不兼容的类型错误,可能是因为我不知道在处理JPG而不是位图时使用什么TBlobType

我把你的建议复制到我的第一个程序中

begin
DISQLite3Database1.DatabaseName := 'C:\Users\Admin\Documents\RAD Studio\Projects\sqlite with photos\testphoto.db';
DISQLite3Database1.Open;
try
strm := TmemoryStream.Create;
strm.LoadFromFile('C:\Users\Admin\Documents\RAD Studio\Projects\sqlite with photos\testpic2.jpg');
Query1.Close;
Query1.selectSQL := ('insert into StudentPhotos(id,photo) values(''sally'', :photo)');
Query1.Params.ParamByName('photo').LoadFromStream(Strm,ftGraphic);
Query1.Open ;
finally
strm.Free ;
  DISQLite3Database1.close;
end;
end;
。。。第一次就成功了

我想有时候在开发的时候,人们看不见树木,看不见树木。
多亏了你们两位,我现在应该能够解决剩下的问题了

你们试过
查询1.Params.ParamByName('photo').LoadFromStream(Strm,ftGraphic)了吗谷歌快速搜索显示:meermor.blogspot.de/2013/07/delphi-load-and-save-image-from-blob.html
procedure TForm1.Button2Click(Sender: TObject);
var
  Strm: TMemoryStream;
  HTTP: TIdHTTP;
  LHandler: TIdSSLIOHandlerSocketOpenSSL;

begin
try
   http:=  TIdHTTP.create;  //make an http component
   LHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
   Strm := TMemoryStream.Create;
   HTTP.IOHandler:=LHandler;
   HTTP.HandleRedirects := true;   
   HTTP.Request.UserAgent := 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)';     try
     Http.Get('https://www.TheUrl.com/picures/Photo.ashx?theid=221' , Strm);
     Strm.Position := 0;
     Strm.SaveToFile('C:\Users\Admin\Documents\testpic2.jpg');
     except
     on e:Exception do
        begin
        ShowMessage(E.ClassName+' error raised, with message : '+E.Message);
          showmessage('could not download file');
          end;
        end;

   finally
      http.Free;
      LHandler.Free  ;
      Strm.free; 
   end;
end;
Query1.Params.ParamByName('photo').LoadFromStream(Strm,ftGraphic);
begin
DISQLite3Database1.DatabaseName := 'C:\Users\Admin\Documents\RAD Studio\Projects\sqlite with photos\testphoto.db';
DISQLite3Database1.Open;
try
strm := TmemoryStream.Create;
strm.LoadFromFile('C:\Users\Admin\Documents\RAD Studio\Projects\sqlite with photos\testpic2.jpg');
Query1.Close;
Query1.selectSQL := ('insert into StudentPhotos(id,photo) values(''sally'', :photo)');
Query1.Params.ParamByName('photo').LoadFromStream(Strm,ftGraphic);
Query1.Open ;
finally
strm.Free ;
  DISQLite3Database1.close;
end;
end;