Just want to know what are the corresponding datatype that I should declare when using DataMapper.
Types in MySQL
smallint
bit
varchar
Can anyone tell me the corresponding type in DataMapper?
Thanks.
According to this site you are fairly limited with no specific equivalents. Varchar somewhat equals string and integer seems to take the place of bigint. Bit is not mentioned at all. The idea is born out further by this link (click on show source) where you will see the adapter for MySQL maps the data types similar to above. Again, bit is not mentioned.
Related
It's a bit stupid question, but I don't have enough relevant expirience to answer it myself.
Can a snowflake generated ID (274950720577339394), be bigger then unsigned_long type of integer? (2^64-1)
Just a bit more info. I'd like to store snowflake IDs inside the elasticsearch index, and according to it's integer types there is a unsigned_long which I guess should perfectly fit, and store snowflake as a number. So doesn't it a good idea? Or it's safe to use keyword instead of int types?
No, they can't.
According to this post on Google Groups,
IDs will still be 64-bit unsigned integers
Note that this post was posted in 2010, which is a while ago, but it doesn't seem it was changed.
I am very new to PL/SQL and tried searching for this online with no avail - I would appreciate any help!
I am looking at a procedure that is something along the lines of this:
PROCEDURE pProcedureOne
(pDateOne DATE,
pDateTwo tableA.DateTwo%TYPE,
pDateThree tableB.DateThree%TYPE,
pTypeOne tableC.TypeOne%TYPE,
pTestId tableD.TestIdentifier%TYPE DEFAULT NULL,
pShouldChange BOOLEAN DEFAULT FALSE)
IS
What does '%TYPE' keyword mean in this context?
tableA.DateTwo%TYPE means "the data type of the DateTwo column in the tableA table". You'll see this referred to as an "anchored type" in documentation.
Using anchored types is quite useful for a couple of reasons
If the data type of the table changes, the code automatically gets compiled with the new data type. This eliminates the issue where, say, a varchar2(100) column in a table gets modified later to allow varchar2(255) and you have to look through dozens or hundreds of methods that reference that column to make sure that their local variables are updated to be long enough.
It documents what data you expect to be passed in to a procedure or for a local variable to reference. In large systems, you generally have at least a few concepts that have very similar names but that represent slightly different concepts. If you look at a procedure that has a parameter tableA.DateTwo%TYPE, that can be very useful information if there is a different DateTwoPrime column that represents a slightly different date.
It means to use the data type of the table.column you are referencing. So for example, if tableC.TypeOne is VARCHAR2(10), then that is the datatype assigned to pTypeOne.
It means that the data type of, for example, pDateTwo is to be the same as the data type of tableA.DateTwo.
%TYPE means the field type does not have to be defined because it is going to inherit it from the field's type.
So pDateTwo doesn't require its own type definition because it will have to same type as tableA.DateTwo.
I'm working with an open source database. I'm trying to map it to classes with DataMapper, and later I'm going to make changes in a Model driven approximation instead of a Database driven one.
But first I would like to map the open source database in an exact way. This database is a PostgreSQL one and in some tables there are some fields with a character type.
How can I map character type in DataMapper? This type it's not in its primitive types, nor in dm-types, nor in dm-types-legacy.
If it gives more information, actually I'm not writing the model by hand but I'm using dm-is-reflective, which automatically maps an existing database table. It gives me following error:
/var/lib/gems/1.9.1/gems/dm-is-reflective-1.0.0/lib/dm-is-reflective/is/adapters/data_objects_adapter.rb:141:in `reflective_lookup_primitive': bpchar not found for DataMapper::Adapters::PostgresAdapter (TypeError)
EDIT
It was a problem with dm-is-reflective and not with datamapper core, which can work well with char type as a String type with a length set. I answer with the solution to the problem.
godfat, the man working in dm-is-reflective quickly solved this issue :) Many thanks to him!
https://github.com/godfat/dm-is-reflective/issues/3#issuecomment-5726650
I have a little problem with Enterprise Architect by Sparx System.
Im trying to model database schema for Oracle. I created table with primary key with data type long. But when im trying to modify column properties (set AutoNum = true) I see empty properties. I read documentation of EA and saw that I need to setup this property to generate sequence syntax.
When I change data type to number, or switch database to mysql (for example) everything is alright, there are properties so Im able to modify AutoNum value.
Did you had similar problem and found solution ? or maybe im doing something wrong.
regards
It's becouse Oracle use sequence instead of autoincrement option. I've checked it and I think you have to use NUMBER column type and then set AutoNum property (you have to select Generate Sequences in options to get proper DDL code too). Instead of LONG data type you can set PRECISION and SCALE options on NUMBER type ie NUMBER(8) mean you can have 8 digits number and it can be set up to 38, so if you don't want to store info about every star in the universe will be enought for your scenario :)
I currently use INT as type for primary key in JavaDB (Apache Derby), but since I'm implementing an distributed system I would like to change the type to java.util.UUID. A few questions about this:
What datatype in JavaDB/Derby should I use for UUID? I have seen CHAR(16) FOR BIT DATA been mentioned but I don't know much about it. Is VARCHAR(16) an alternative?
How should I use it with JDBC? E.g. in an PreparedStatement, how should I set and get an UUID?
If I later would likte to change database to SQL Server, is there a compatible datatype to java.util.UUID?
Simply, How should I use UUID with JavaDB/Derby and JDBC?
UUID is a 128 bit value. The CHAR(16) FOR BIT DATA type reflects that it is bit data stored in character form for conciseness. I don't think VARCHAR(16) would work because it doesn't have the bit flag. The database would have to be able to convert the binary data to character data which deals with encoding and is risky. More importantly, it wouldn't buy you anything. Since a UUID is always 128 bits, you don't get the space savings from using VARCHAR over CHAR. So you might as well use the intended CHAR(16) FOR BIT DATA.
With JDBC, I think you use the get/setBytes() method since it is dealing with small amounts of binary data. (Not positive, would have to try this)
And no idea about the SQL Server part.
If you still want to use the UUID object in your code you can use fromString to create UUID objects from the DB and toString to store them in the DB.
You could convert the UUID to a string and store it as VARCHAR. Most UUID string formats are similar to this one: 32 digits separated by hyphens: 00000000-0000-0000-0000-000000000000, so then you'd want a VARCHAR(36), or make it something like VARCHAR(64) if you please, since it doesn't hurt to have extra 'space' available in your VARCHAR -- only the actual digits are stored.
Once you've converted it to a string, just call Statement.SetString to include it in your INSERT statement.