Recent

Author Topic: How save a picture to SQLite table?  (Read 533 times)

magleft

  • Full Member
  • ***
  • Posts: 111
How save a picture to SQLite table?
« on: March 28, 2023, 03:47:37 pm »
With the help of LAMW's examples I am trying to create an application that among other things will take a photo and store it in the last record of a sqlite table. The table structure is:
   CREATE TABLE [EPISKEPSI4](
   [IDEPISK3] INTEGER PRIMARY KEY AUTOINCREMENT,
   [MERA] DATE DEFAULT CURRENT_DATE,
   [FIGURE] BLOB,
   [ID_REF] INTEGER);

While it saves other elements in the table, it saves the photo in the DCIM folder, it does not save the photo in the table.
What am I doing wrong;


Code: Pascal  [Select][+][-]
  1. procedure TFvisitland.Button16Click(Sender: TObject);
  2. begin
  3.   if IsRuntimePermissionGranted('android.permission.CAMERA') and
  4.      IsRuntimePermissionGranted('android.permission.WRITE_EXTERNAL_STORAGE') then
  5.   begin
  6.       Camera1.Filename :='vis_'+inttostr(10)+'_'+FormatDateTime('ddmmyyyyMMssSSS',now())+'.jpg'  ;
  7.       Camera1.RequestCode := 12345;
  8.       Camera1.TakePhoto;
  9.   end
  10.   else  ShowMessage('Sorry... Some Runtime Permission NOT Granted ...');
  11. end;
  12.  
  13. procedure TFvisitland.FvisitlandActivityResult(Sender: TObject;
  14.   requestCode: integer; resultCode: TAndroidResult; intentData: jObject);
  15. var
  16.   photoPath: string;
  17.   photo_id:integer;
  18. begin
  19.   if resultCode = RESULT_CANCELED then
  20.   begin
  21.     ShowMessage('Photo Canceled!')
  22.   end
  23.   else if resultCode = RESULT_OK then //ok...
  24.   begin
  25.     if requestCode = Camera1.RequestCode then
  26.     begin
  27.       photoPath:= Camera1.FullPathToBitmapFile ;
  28.       DbVisitLandPhoto.close;
  29.       DbVisitLandPhoto.OpenOrCreate('ApkAgros.db');
  30.       DbVisitLandPhoto.select('Select max(IDEPISK3) from Episkepsi4;') ; // Find Last record
  31.       photo_id:=DbVisitLandPhoto.Cursor.GetValueAsInteger(0)    ;
  32.       DbVisitLandPhoto.close;
  33.       DbVisitLandPhoto.OpenOrCreate('ApkAgros.db');
  34.       DbVisitLandPhoto.UpdateImage('EPISKEPSI4','FIGURE','EPISK3',photopath,photo_id);
  35.       DbVisitLandPhoto.close;
  36.     end;
  37.   end
  38.   else
  39.     ShowMessage('Photo Fail!');
  40. end;
  41.  
  42.  
windows 10 64

rsu333

  • Full Member
  • ***
  • Posts: 110
Re: How save a picture to SQLite table?
« Reply #1 on: April 02, 2023, 08:15:39 am »
Please ref demo app [sqlitedemo all 4 as well as grid demo]

magleft

  • Full Member
  • ***
  • Posts: 111
Re: How save a picture to SQLite table?
« Reply #2 on: April 10, 2023, 04:19:32 pm »
I already tried to modify the examples but I failed to insert the camera photo into the database.
I also tried saving the photo in png format and then updating the database but it didn't work.
I can't figure out what I'm doing wrong.
windows 10 64

 

TinyPortal © 2005-2018