|
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
|
|
|
|
|
I dont know the other way.
I saw in all the code example that i need create subclassing Datacontext and with this subclassing to call the InsertAllOnSubmit and SubmitChanges method.
Please tell me where i wrong.
|
|
|
|
|
And therein lies the problem, trying copy and paste code you don't understand.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
We have a couple of instances where this has come up in the past and now dealing with another and thought it'd be good to get input on what everyone's best recommendation and real-world experience has been with the following scenario:
1. Consider a situation where you have a single database entity that you want to relate to many other database entities.
2. For example, a table called "CommunicationLog", which is intended to store details (comments, user, date/time, etc.) related to communication with a Customer
3. However, in addition to storing the communication details in relation to the Customer, we also want to relate these records to other entities. For example, we want to identify if this communication is related to a specific Product, a Work Order, a Sales Order, a Quote, a Contract, another Employee, etc.
4. The entity we're referring to in #1 is intended to be very generic so we want it to be in one table rather than having a table for each of the entities in #3 (eg. SalesOrderCommunicationLog, WorkOrderCommunicationLog, etc). Why do we want this in one table?
4a. Maintainability - we see no reason to create multiple tables that are doing the same thing, when the only thing that differentiates each record is what the record relates to.
4b. By allowing a communication log record to be related to multiple entities it's more powerful - we're able to identify a customer complaint, for example, not only by customer, but also with a specific work order, product, etc.
4c. Having all these details in one table makes it easier to search and cross-reference comments that may be related to multiple specific identities
So hopefully that explains what we're trying to accomplish. My question is, what is the best way of implementing this, based not only on proper database form, but also considering real-world scenarios.
Here are the two approaches we've been looking at (but if you have another idea I'd be interested to hear):
Approach 1. Add a field for each new entity that this record relates to - this ensures good database integrity, but it also means that tables, relationships, stored procedures and other code need to be added/altered every time we decide that we want the Communication Log record to relate to another entity AND it results in a table with 10+ fields, of which many may be left null for a lot of the records.
Approach 2. Create a "CommunicationLogRelated" table with fields for CommunicationLogID, RelationType, and RelationID. RelationType would be used to identify the other entity that this CommunicationLog record is related to and RelationID is used to identify the PK of the other entity. The clear advantage to this is a "cleaner" table design and much easier to add new related entities. However, we lose referential integrity. I'm also not sure if there's a performance benefit to one approach vs. the other.
I've looked for patterns, but have not had any success in finding a pattern that mimics the above scenario. I'd really appreciate feedback on this, especially if you've implemented something like it in the past.
Cheers,
Chris
|
|
|
|