@reptar said:
Logarithms are your friends...
Couldn't agree more!
If Ceil(Log(number)) = 6 Return true
( pseudo-code, lol )
@reptar said:
Logarithms are your friends...
Couldn't agree more!
If Ceil(Log(number)) = 6 Return true
( pseudo-code, lol )
STOP USING DATABASES FOR TEMPORARY STORAGE.
What do you use as temporary storage when you face a problem that leaves you no other choice?
Hi smartest people of the world! lol
It's not an immediate problem, but it's something I face from time to time. Let's say that I have a situation in that records referencing to one 'main' record in another table may need to be added before the user actually confirms the creation (and, therefore, the transaction is commited) of the 'main' record. A simple example of that could be an image gallery:
Let's say that I have a table called 'pictures' and a table called 'galleries'. How would I make it possible to the user to (supposing in this example that it's a web app) enter the Gallery Creation Page (GCP) and add images to this gallery before submitting the form and actually create the record in the galleries table?
When this happens to me, I usually make the database create a blank record the moment the user enters the GCP. The downsides of this is that, this way, I can't use the database's built-in data consistency and that it leaves blank records in the database if the user abandons the GCP, as when s/he clicks the GCP link for mistake.
The other solution I've also done is not using auto-increment in the primary key at all. To create new records, I usually create a small function that gets the MAX() of the ID field and sums one. This is, at least for me, niftier than the others, but it still has downsides: if the user adds any relative records (pictures) but cancels the main operation (gallery creation), the relative records (pictures) will become orphan, and worse, they will relate to the next main record (gallery) created, as MAX(ID) + 1 will not change as no records have been added because the operation has been cancelled. Also there is a data concurrency problem: if Alice and Bob (A and B) enter the page at the same time, MAX(ID) + 1 will have the same value for both until one of them confirms the operation. Worse, if A adds relative records (pictures), but B confirms the main record (gallery) creation before, A's relative records will relate to B's main record, and no relative records that A added will relate to her own main record.
Well, this is the (long) description of the problem. How do you guys deal with this? Any suggestions welcome. =)
PS: sorry for making such a prolix explanation, but I simply couldn't reduce it to be simpler without making it clear. Hope you don't get lost in the texts!
Sure! But it's still a WTF, you know =)