I'm trying to use the drift library (renamed from moor) ,but it's unable to create tables because of this error:
SqliteException(1): parameters prohibited in CHECK constraints, SQL logic error (code 1)
CREATE TABLE IF NOT EXISTS enterprise (name TEXT NOT NULL CHECK(LENGTH(name) <= ?), ..other fields);
This is the table class causing the error:
class Enterprise extends Table {
TextColumn get name =>
text().check(name.length.isSmallerOrEqualValue(maxNameLength))();
// ...other fields
}
The error goes away if I remove the check. Could someone explain why the check isn't working ?
Turns out it's a bug with drift. This is the workaround as suggested by the author of drift, and will be fixed in a future release.
Replace
check(name.length.isSmallerOrEqualValue(maxNameLength))
With this:
check(name.length.isSmallerOrEqual(Constant(maxNameLength)))
Related
I have looked at examples online on how to create a geometry field with peewee and this is what I came up with so far:
class GeometryField(Field):
db_field = 'geometry'
def db_value(self, value):
return fn.ST_GeomFromGeoJSON(value)
def python_value(self, value):
return fn.ST_AsGeoJSON(value)
I have added this definition to a table like so:
class GeoJSON(BaseModel):
geojson_id = UUIDField(primary_key=True, default=uuid.uuid4)
geometry = GeometryField()
Now, this thing wouldn't run and I don't understand what I missed to make it happen.
My aim is to manage insertions of geometric entities into the DB so that later I can make use of PostGIS to query based on locations.
The error I'm getting in the init phase:
peewee.ProgrammingError: syntax error at or near "NOT" LINE 1:
...geojson_id" UUID NOT NULL PRIMARY KEY, "geometry" NOT NULL)
I init the table like so:
GeoJSON.create_table("geojsons")
What did I miss here? Did I need to do anything else before this geometryfield can be used?
Is there a secret geom field that Peewee supports out of the box that I don't know about?
The problem was that the DB failed to install PostGIS and therefore didn't recognize the geometry field from the DB.
Once I fixed that and had the extension installed, the solution above worked perfectly.
If you are coming back to this question later. The Peewee Syntax has changed since version 3.0. db_field has changed to field_type.
So to get it working:
Make sure you install the PostGIS extension on your postgres database.
CREATE EXTENSION postgis;
Create a custom field.
class GeometryField(Field):
field_type = 'geometry'
def db_value(self, value):
return fn.ST_GeomFromGeoJSON(value)
def python_value(self, value):
return fn.ST_AsGeoJSON(value)
Use the custom field in your model
class GeoJSON(BaseModel):
geojson_id = UUIDField(primary_key=True, default=uuid.uuid4)
geometry = GeometryField()
Peewee Docs
Documentation describes possibility to do regexp constraints:
ALTER PROPERTY Account.gender REGEXP "[M|F]"
I always receive exception:
com.orientechnologies.orient.core.command.OCommandExecutorNotFoundException:
Cannot find a command executor for the command request: ...
Every other thing works. Did you have this problem? How did you fix it? Should I create an issue?
EDIT:
I use version 2.2.18. I was trying to execute this code:
CREATE CLASS Account extends V;
CREATE PROPERTY Account.Gender STRING (MANDATORY TRUE, MAX 20, REGEXP "[M|F]");
I also don't see regexp option when inspecting scheme in studio. There is everything else: mandatory, read only, not null, min, max, collate, etc... but no regexp.
Did you create the Account class and the gender property before doing this request?
This is working :
CREATE CLASS Account extends V
CREATE PROPERTY Account.gender STRING
ALTER PROPERTY Account.gender REGEXP "M|F"
EDIT :
You actually can't do it in one request (you need to alter the property to add regexp) I don't think it's normal so you can create an issue.
Hope it helps
I have an existing app that I am trying to upgrade from MVC5/EF6 to MVC6/EF7. We dynamically create some of our SQL tables, and as a result, have made use of the
System.Data.Entity.Database.SqlQuery
method to automatically map to entities that we use throughout our application.
This method seems to have gone away (i.e. not part of
Microsoft.Data.Entity.Infrastructure.Database ) in EF7 (or is not yet implemented). Are there plans to re-implement this method in EF7 or is there another way to accomplish this? Our project is kind of dead in the water until we figure this out.
Edited on May 20, 2015
I've been trying to make this work with FromSql, since that's what's available in Beta4, but no matter what combination of concatenated string, parameters I try, I keep getting different versions of an "Incorrect Syntax near #xxxvariable" message.
var results = Set<AssessmentResult>().FromSql("dbo.GetAssessmentResults #FieldA='Data1', #FieldB='Data2', #UserId = 2303");
var results2 = Set<AssessmentResult>().FromSql("dbo.GetAssessmentResults #FieldA= {0}", intData);
Both of these calls result in
"Incorrect syntax near '#FieldA'"
Any ideas?
We recently introduced the .FromSql() extension method on DbSet. It has the added benefit that you can continue composing LINQ on top of it.
var customers = db.Customers
.FromSql("SELECT * FROM Customer")
.Where(c => c.Name.StartsWith("A"));
This is my code. I have to set the default value for Account fields like Name ,Phone etc...but it shows some error.
trigger setDefaultAccountValues on Account (before insert, before update){
for (Account acc : trigger.new){
acc.Name ='xxx';
}
}
The error is:
Error: Compile Error: Variable is not visible: name at line 5 column 9
How to resolve this?
I'm assuming that this is Apex, so check out this tutorial: How to write a trigger in Apex.
[UPDATE]
Most probably you need to add the public (or global) access modifier to the Name (or name, since Apex is case insensitive) variable in the Account class.
Haven't seen this error before, and a cursory web search turns up very little. Here's (I think) the offending code:
this.HasMany(a => a.ListItems).WithRequired()
.Map(m =>
{
m.MapKey("AttributeId");
m.ToTable("ProductAttributeListItem");
}
)
;
And here's the full error:
The specified table 'ProductAttributeListItem' was not found in the
model. Ensure that the table name has been correctly specified.
The table is there and spelled correctly.
The lack of search results makes me think I'm missing something obvious. What might that be?
If you want to define the table name of the entity ListItems is refering to you need to do that on the entity, not in the relationship mapping:
modelBuilder.Entity<ListItem>() // or whatever the entity is called
.ToTable("ProductAttributeListItem");
And remove m.ToTable from the Map action.