LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 11-12-2006, 11:35 PM   #16
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 10.04, Crunchbang Statler
Posts: 3,325

Rep: Reputation: 168Reputation: 168

Very basic (pseudo code)
Write program:
Code:
store_sql()
{
  // try to lock file
  while (!acquire_lock());
  // write buffer with sql to file
  while(sql_in_buffer())
  {
      write_sql_to_file();
  }
  // release lock
  free_lock();
}
Read program:
Code:
read_sql()
{
  // try to lock file
  while (!acquire_lock());
  // read whole file (and empty it)
  read_sql_from_file();
  // release lock
  free_lock();
  // process sql statements
  while(sql_to_do)
  {
    // something usefull here
  }
}
The write-program tries to lock the file in an endless loop till it succeeds.
Next it writes one sql line to the file and releases the lock (so the read program can read when it when necessary).

The read program attempts to get a lock on the same file. As long as the write-program is writing, it can't get the lock. Once it gets the lock, it reads the whole file and empties it. Next it releases the lock so the write-program can write again.

There are some points:
If you forget to free the lock, you may end in a situation where one of the two programs does no longer work.
The write-program must be a bit more intelligent. In above function, it 'hangs' till it can get the lock; you probably want it to gather more sql statement to write to file.

Hope this helps.
 
Old 11-13-2006, 06:49 PM   #17
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,282

Rep: Reputation: 61
You could also use another mysql table to store the queries
 
  


Reply

Tags
buffer


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
reading and writing floppydisks anatman Linux - Newbie 3 05-22-2006 12:32 AM
writing and reading from a file! sahel Programming 1 12-27-2005 01:33 PM
C File reading and writing AbhishekSamuel Programming 3 05-03-2005 03:59 PM
Help reading and writing to file xiste Programming 1 04-15-2005 12:43 AM
Reading and Writing DVD media elsabio Fedora 2 03-06-2005 06:25 PM


All times are GMT -5. The time now is 06:13 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration