Accessing programatically to attribute length in run-time
Accessing programatically to attribute length in run-time
- Subject: Accessing programatically to attribute length in run-time
- From: "Txinto Vaz" <email@hidden>
- Date: Wed, 21 Feb 2007 13:47:13 +0000
Hi, I am developing a program using Core Data.
I explore the entities and properties of the model in runtime, and have a
routine that replicates the model in a data base, creating the mirror
tables. My ambition is to build a "sinchronize" action between the Core
Data application and the SQL database, and I use the programatic exploration
of the model to create the table architecture in the database.
Everything works fine except I have found no way to know the length of the
string fields to be created in the database. I think a good idea is to use
the validation argument "max length" of the model to define this length. In
runtime I can check this value and use it in the CREATE TABLE sentence. But
the problem is that I don't know how to access to this value (if it is
possible).
In the following code (that works fine) I access to the attribute type and
generate a string. The length is always 32 and I want to change this to the
"max value" in the attribute validation field, which is set in the model.
Thank you for your time.
Tx.
NSDictionary *atributos = [entidad attributesByName];
NSArray *keys=[atributos allKeys];
NSEnumerator *enumkeys = [keys objectEnumerator];
id current_key;
id createAtributos=[NSMutableString stringWithString:@" `ident` INT
UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY"];
while ((current_key = [enumkeys nextObject]))
{
// Attribute process
switch ([[atributos valueForKey:current_key] attributeType])
{
case NSInteger64AttributeType:
[createAtributos appendFormat:@", `%@` INT(64) UNSIGNED NOT
NULL",nombre];
break;
case NSDoubleAttributeType:
[createAtributos appendFormat:@", `%@` DOUBLE NOT NULL
DEFAULT '%lf'", nombre, [[[atributos valueForKey:nombre] defaultValue]
doubleValue]];
break;
case NSStringAttributeType:
// I want to change this '32' by the 'Max Value' in the attribute model.
[createAtributos appendFormat:@", `%@` VARCHAR( %d ) NOT
NULL DEFAULT '%@' ", nombre,32 ,[[[atributos valueForKey:nombre]
defaultValue] doubleValue]];
break;
....
}
}
...
id createQuery=[NSString stringWithFormat:@"CREATE TABLE `%@` ( %@ )
ENGINE = innodb'",[entidad name],createAtributos];
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden