|
That's "generating a number" and "verify it's occurance". For that you'd need;
An efficient way of generating a number
An efficient way of looking up a number (index the field!!)
Or, more efficient, use an auto-incremented[^] column. Isn't type BigInt allowed in MySql? Something like below, if I adapted the example correctly;
CREATE TABLE animals
(
id BIGINT NOT NULL AUTO_INCREMENT,
name CHAR(30) NOT NULL,
PRIMARY KEY (id)
) ENGINE=MyISAM;
I are Troll
|
|
|
|
|
Now what happened to GUIDs? and where are PIEBALD's sequences? he isn't building a snowman, is he? we need him here.
|
|
|
|
|
Sequences? Isn't that Oracle? There's an autoincrement-column in MySql, sounded logical to me to abuse that.
He's probably setting up the different components for an extendible snowman
I are Troll
|
|
|
|
|
I was hinting at an earlier thread, found it here[^].
|
|
|
|
|
Eddy Vluggen wrote: extendible snowman
extensible !!
A snowman from which all other snowfolk can be derived?
Maybe I should look into a Turing Snowman or an Analytical Snowman.
|
|
|
|
|
Buy a large cooler, otherwise it'll overheat during parallel tasks
I are Troll
|
|
|
|
|
Actually, I was at a play rehearsal. It's good to be the king.
I did see the post earlier, but I didn't feel like chiming in. Plus, he said "random", so I didn't think a sequence would work.
I suppose one might be able to generate a GUID and use only 64 bits of it; RowID , convert to char , substring , convert to big int...
|
|
|
|
|
Thank you, your majesty.
|
|
|
|
|
If you want to make sure it is unique, I would suggest you use a GUID instead on Int64.
|
|
|
|
|
True Random number generation is an art - most computer generated random numbers are actually periodic and not truly random. But usually "good enough".
See this site for a discussion of a few truly random number techniques.
http://www.random.org/randomness/[^]
They also offer an API to generate true random numbers.
Melting Away
www.deals-house.com
www.innovative--concepts.com
|
|
|
|
|
If you're assigning a random number to every entry in the table (i.e. every single time you add an entry you associate a random number with it) then a good mechanism to use is the LFSR - Linear Feedback Shift Register.
An n-bit LFSR will iterate through 2^n numbers in a fixed (deterministic) sequence (thus, not very random, but it might suit your purposes for uniqueness) and guarantees to loop back to the first number outputted after 2^n iterations. I'm a little rusty on the details, but it should definitely guarantee that you don't exhaust every number for a "long" time.
Xilinx has a good app note on this: http://www.xilinx.com/support/documentation/application_notes/xapp052.pdf[^]
|
|
|
|
|
Assuming you don't want to use a GUID...
Create a table of number ranges; call it RandRanges. These are the numbers that are not yet taken. Generate a random integer (use the Rand function along with some multiplication and addition) between 1 and the number of items in RandRanges. Use that number to select a row from RandRanges. Use the min/max values (i.e., the range) as the min/max of a random integer you will generate. Once you generate that integer, use that number as your desired random number. Then, modify the RandRanges table to take that value out. You can do that by deleting the row you just created and splitting it into two new ranges that you insert into the table.
For example, say RandRanges starts out with:
1: 1-100
2: 101-200
You then generate the random number 2, so you are gonna use the second item in RandRanges.
101-200
Now, you generate a random number between 101 and 200. Say that turns out to be 150. You would take that out of RandRanges:
1:1-100
2:101-149
3:151-200
You then use your unique random number, 150, however you like. This table will grow at about the same rate that you use the unique random numbers, so you don't have to worry too much about space considerations. In fact, the table will sometimes shrink. If you use up all the random numbers (not likely with an Int64 range), the table would become empty.
|
|
|
|
|
Perhaps try to redefine the problem a bit. For example, if it's an activation code then you can make it out of two parts: one sequential part, and a random part. If the sequential part is unique, the activation code will be unique. Of course the drawback is that you can issue less activation codes but I do not imagine that you want to activate 2^64 whatevers
|
|
|
|
|
Uh, I think you meant to post that as a reply to the OP's message and not as a reply to mine.
|
|
|
|
|
I want to know how can I list all database in mysql? and also how to show all tables within the selected database?
|
|
|
|
|
You can't (as far as I know).
List tables (if I recall correctly).
Edit: It's show tables and also describe <table>
|
|
|
|
|
Having limited (none) experience with mysql I can only recommend that you look into the system table, sql server has a master database that stores the db information, I'm pretty sure mysql will have something similar.
There should be system tables that hold the meta data for the database somewhere in mysql, research will be required. There are lots of responses from Google for this enquiry.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
jrahma wrote: I want to know how can I list all database in mysql?
By keeping track if the tables you make. Create a tabled called "MyTables", and add an entry whenever you successfully issue a CREATE command
I are Troll
|
|
|
|
|
Im using the object DataContext to save some object to DB. I see that the object presistence is Ok - but after i stop the debug and i recompile it - i dont see the object anymore.
The saving action that i did:
dataContext.table.InsertOnSubmit( someObject);
dataContext.SubmitChanges();
modified on Sunday, December 5, 2010 7:56 AM
|
|
|
|
|
If they've been persisted, query them back.
|
|
|
|
|
I impliment the InsertCustomer method - the code :
<br />
void InsertCustomer(Customer instance)<br />
{<br />
this.ExecuteDynamicInsert( instance ); <br />
}<br />
And still nothing saved in the DB file.
|
|
|
|
|
That's not what you said in the original post.
|
|
|
|
|
|
Sorry ... i did not said that dataContext is define in the code below
public partial class dataContext : System.Data.Linq.DataContext
{
....
}
|
|
|
|
|
Yes, of course you are subclassing DataContext. I understood that. Would like to answer the question now?
I know the language. I've read a book. - _Madmatt
|
|
|
|