Datamapper type for char (aka character) field type - ruby

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

Related

DataMapper datatype

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.

Enterprise Architect Oracle long field column properties

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 :)

How to Get Primary Key and Unique Constraint Columns in Derby

How does one do this? The SYSCOLUMNS system table only has columns for tables. SYSCHECKS has a REFERENCEDCOLUMNS object. Is there any way to get this.
I'm aware of the JDBC getPrimaryKeys call, but that doesn't get unique constraint columns.
Derby - constraints
It took some digging to find the above question; my question is a partially answered follow-up question to the one above.
Taking the CONSTRAINTID against SYSKEYS gives a CONGLOMERATEID, which when taken against SYSCONGLOMERATES yields a DESCRIPTOR. The DESCRIPTOR is a POJO that contains an int-array in the baseColumnPositions method. This int-array contains the COLUMNNUMBERS in SYSCOLUMNS of the columns in the constraint.
If querying in straight SQL, getting the DESCRIPTOR field yields a string with a CSV list of ints that have to be parsed. Fortunately for me, I happen to be working in Clojure, so calling the baseColumnPositions method and using the resulting int-array are trivial.

iterating over linq entity column

i need to insert a record with linq
i have a namevaluecollection with the data from a form post..
so started in the name=value&name2=value2 etc.. type format
thing is i need to inset all these values into the table, but of course the table fields are typed, and i need to type up the data before inserting it
i could of course explicitly do
linqtableobj.columnproperty = convert.toWhatever(value);
but i have many columns in the table, and the data coming back from the form, doesnt always contain all fields in the table
thought i could iterate over the linq objects columns, getting their datatype - to use to convert the appropriate value from the form data
fine all good, but then im still stuck with doing
linqtableobj.columnproterty = converted value
...if there is one for every column in the table
foreach(col in newlinqrowobj)
{
newlinqobj[col] = convert.changetype(namevaluecollection[col.name],col.datatype)
}
clearly i cant do that, but anything like that possible.. or
is it possible to loop around the columns for the new 'record' setting the values as i go.. and i guess grabbing the types at that point to do the conversion
stumped i am
thanks
nat
If you have some data type with a hundred different properties, and you want to copy those into a completely different data type with a hundred different properties, then somehow somewhere in your code you are going to have to define a hundred different "mapping" instructions. It doesn't matter what framework you are using, or whether the "mapping" instructions are lines of C# code, XML elements, lambda functions, proprietary "stuff", or whatever. There's no getting away from it.
Bearing that in mind, having one line of code per property looks to me like the fastest, simplest, most readable and maintainable solution.
If I understood your problem correctly, you could use reflection (or dynamic code generation if it is performance sensitive) to circumvent your typing problems
There is a preety good description of how to do something like this at codeproject.
Basically you get a PropertyInfo for the property you want to set (if it's not a property I think you would need dynamic code generation) and use it's setValue method (after calling the appropriate Convert.ChangeType of course). This will basicall circumvent the whole static typing, so there you are.

LINQ FormatException

I currently have an existing database and I am using the LINQtoSQL generator tool to create the classes for me. The tool is working fine for this database and there are no errors with that tool.
When I run a LINQ to SQL query against the data, there is a row that has some invalid data somehow within the table and it is throwing a System.FormatException when it runs across this row. Does anyone know what that stems from? Does anyone know how I can narrow down the effecting column without adding them one by one to the select clause?
Do you have a varchar(1) that stores an empty string?
You need to change the type from char to string in the designer (or somehow prohibit empties). The .net char type cannot hold an empty string.

Resources