Is there any one using Simple.Data ORM https://github.com/markrendle/Simple.Data. Any idea how to implement alias column names and table names for all the DML operation. I've referred http://simplefx.org/simpledata/docs/ . It talks about alias in Select query? I'm looking for something like config file which holds alias column/tables names
I'm afraid Simple.Data doesn't have a mechanism for using the same aliases for columns and tables again and again. You have to use the As method to use aliases each time you make a query. So for column aliases, have a look at http://simplefx.org/simpledata/docs/pages/Retrieve/ColumnAliasing.html and for table aliases for use in join queries, have a look at the section on Explicit Joins at http://simplefx.org/simpledata/docs/pages/Retrieve/LazyLoadingJoins.htm
Related
My Querybuilder statement looks like this:
$qb->from('models\Order', o');
$qb->innerJoin('o.fStatus', 'fs');
$qb->select('COUNT(o.id), PARTIAL fs.{name, id}');
If I run this I get the error
SELECT COUNT(o.id),': Error: Cannot select entity through identification variables without choosing at least one root entity alias.
However, if I change my select statement to either of these:
$qb->select('PARTIAL o.{id}, PARTIAL fs.{name, id}');
$qb->select('COUNT(o.id), fs.name, fs.id');
The query will run.
Why can I not select from the root entity and also a partial object that has been joined to it?
Doctrine gives a bit of explanation in their documentation:
A common mistake for beginners is to mistake DQL for being just some form of SQL and therefore trying to use table names and column names or join arbitrary tables together in a query. You need to think about DQL as a query language for your object model, not for your relational schema.
When you select using DQL or the QueryBuilder, it is traditionally expecting you to select the root entity (the one in your FROM clause), or some combination of columns/aggregates (COUNT, SUM, etc.). When you select a partial object from a joined table but don't select the root entity, Doctrine doesn't know how to hydrate - what if there is a one-to-many/many-to-one, how does it return the data? It won't make those assumptions.
Doctrine by default does not allow partial objects. It seems like you would be better off just returning columns for your query since that's really what you're looking for in that case.
Others have worked around the issue using the WITH clause - see Doctrine query distinct related entity.
Is there any way to add multiple column in a single statement in ORMLite.
Although i have gone through this Sqlite question: sqlite alter table add MULTIPLE columns in a single statement
And according to this link there is no way in Sqlite but as ORMLite is a wrapper on sqlite as per my knowledge, is there any way to add multiple columns in a single statement like we do in sql:
ALTER TABLE table_name
ADD (column_1 column-definition,
column_2 column-definition,
...
column_n column_definition);
Thanks in advance!!
So Finally after a lot search i don't think that there is any way to put multiple column in a single statement in OrmLite as SQLite does not support multiple iteration for ADD keyword.
Thanks for the answer SQLite alter table
and even it's mentioned in the doc SQLite docs
Is there any way to add multiple column in a single statement in ORMLite
Any schema changes in ORMLite will have to be done using the Dao.executeRaw(...) method which just runs raw statements on the database and returns the number of lines changed (as reported by the database).
If Sqlite supports the alter statement then you should be able to do something like:
dao.executeRaw("ALTER TABLE table_name ADD (column_1 column-definition,"
+ " column_2 column-definition,"
+ " ...,"
+ " column_n column_definition);
Here it says that if I specify an INTEGER PRIMARY key column it will be used as an alias for rowid. For normal tables it works well, but for virtual FTS tables it does not.
Is there a way to use a rowid alias somehow?
Im using SQLite on Android and I would like to use the _id name for this column.
Thanks
That documentation applies only to 'real' SQLite tables.
With FTS tables, data types are ignored; all columns are intended to be used for text.
FTS tables do have an internal rowid column (also called docid), but it is not possible to rename it.
I tried INSERT OR REPLACE INTO, but it doesn't preserve the row id when it replaces the record to update it. Another option is do it in two steps: INSERT OR IGNORE INTO then UPDATE, but I would prefer a one step solution. So I am wondering if SQLite has something like the MERGE keyword or other simple solutions?
No, SQLite doesn't support MERGE or upsert.
You can use your two-step solution, but what you probably really want is for the ROWID to be a first-class column in your table. If you declare a column as INTEGER PRIMARY KEY, it will be an alias for the ROWID. Then INSERT OR REPLACE will work fine.
You can get a list of databases using
PRAGMA database_list
or a list of tables in the "main" database using
select name from sqlite_master where type='table'
but as I just wrote, it only returns the tables from the "main" DB only, and I don't see a way to know which tables are in the other DBs.
So how does one list the tables in the other DBs (which were attached later on)?
Thanks, --DD
PS: I can think of a work around of creating a separate sqlite* for each DB listed via the pragma database_list, and them doing the "select name from sqlite_master where type='table'" N times on those (since each one is the "main" one now), but this sounds like something that should be possible without resorting to the work-around, no???
Ah ah, found the answer by looking at the answer for How do I open an in-memory database file into sqlite3
Since there's a sqlite_master per DB, all I need to do is prefix sqlite_master with "DB_name." where DB_name corresponds to the name column returned by PRAGMA database_list.