[support] Database query cache issue
Kamal Palei
palei.kamal at gmail.com
Mon Aug 27 01:32:06 UTC 2012
Hi Jamie Holly
Thanks for kind reply.
You are right, I just deleted the entry and added a new entry in files
table, it looks fine.
I have a small concern. The 'fid' column in files is of type serial. But I
do not want unnecessary increment of fid values. For that purpose, while
inserting new record, I am just making use of last fid value of that user.
Code as below
db_query("INSERT INTO {files} (fid, uid, filename, filepath, filemime,
filesize, status, timestamp) VALUES (%d, %d, '%s', '%s', '%s', %d, %d,
%d)", $LastFID, $file->uid, $file->filename, $file->filepath,
$file->filemime, $file->filesize, $file->status, $file->timestamp);
Hope I am not doing any mistake while re-using last FID value.
Regards
Kamal
NECS, Bangalore
On Sun, Aug 26, 2012 at 8:09 PM, Jamie Holly <hovercrafter at earthlink.net>wrote:
> You aren't deleting the record from the database, just the file from the
> file system. You should add in there a:
>
> db_query('DELETE FROM {files} WHERE fid = %d', $FID);
>
> Also do that on any other linked tables you have added in.
>
> Jamie Hollyhttp://www.intoxination.net http://www.hollyit.net
>
> On 8/26/2012 10:25 AM, Kamal Palei wrote:
>
> Hi All
> I am using Drupal 6.26.
>
> I am trying to upload a file. One user can upload only one file.
> After a while, if user wants to upload another file, I need to delete the
> first file and upload the second file.
> To delete the first file, I do a query to get the first file name, deletes
> first file and uploads the second file.
> After a while, if user wants to upload another file, when I do query to
> get the second file name (as I want to delete the second file now), I
> always get the first file name.
> So I am not able to delete the second file.
>
> Probably database cache plays a role here, how can I make sure, my query
> returns the latest data present in table, query should not pick the data
> from cache.
>
> Please refer code below.
>
> global $user;
> $FID = -1;
>
> $result = db_query("SELECT fid, filepath FROM {resubmt_table} LEFT JOIN
> {files} USING (fid) WHERE resubmt_table.uid = %d", $user->uid);
> $obj = db_fetch_object($result);
> if($obj)
> {
> $FID = $obj->fid;
> if($obj->filepath)
> {
> if(file_exists($obj->filepath))
> {
> drupal_set_message("File exists deleting " . $obj->filepath);
> unlink($obj->filepath);
> }
> else
> {
> drupal_set_message("File does not exists, so not able to delete, file
> = " . $obj->filepath);
> }
> }
> }
>
>
> Many times, I am not able to delete the file.
> Please suggest how can I fix this issue.
>
> Thanks
> Kamal
> NECS, Bangalore
>
>
>
>
>
>
>
> --
> [ Drupal support list | http://lists.drupal.org/ ]
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20120827/e731c8ae/attachment-0001.html
More information about the support
mailing list