Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Computed columns and extras like COLLATE #12

Closed
SelvinPL opened this issue Oct 23, 2014 · 13 comments
Closed

Computed columns and extras like COLLATE #12

SelvinPL opened this issue Oct 23, 2014 · 13 comments

Comments

@SelvinPL
Copy link

what about computed columns ... i know we have a views and it is a lots of works since you are using projection parameter from CP.query as columns in db.query without mapper... take a look at my(runtime) generator documentation and search for computed https://selvinlistsyncsample.codeplex.com/documentation ...(also you can add extras to the Column like Column.COLLATE) ...

@hamsterksu
Copy link
Owner

about computed columns:
what do you mean? a + b as c? sum(a) as c?

@hamsterksu
Copy link
Owner

if you want to select value and make some actions in the select you just need to provide projection to CP.query

Example:

String[] projection = new String[]{"LTRIM(RTRIM(" + YourTable.Name+ " || ' ' || " + YourTable.Description + "))"}

cp.query(uri, projection, ........)

@hamsterksu
Copy link
Owner

if you want to define this expression in databse query you can use RawQuery

@hamsterksu
Copy link
Owner

also i have a plugin for my library: https://github.com/hamsterksu/annotatedsql-projection-plugin
you can define projection in table/view/query definition

Example:

@Projection("LTRIM(RTRIM(" + YourTable.Name+ " || ' ' || " + YourTable.Description + ")) as super_value")
String MY_SUPER_PROJECTION = "Super"

@SelvinPL
Copy link
Author

ok, plugin, just delete this issue but still it will be good to point the projection plugin on main page https://github.com/hamsterksu/Android-AnnotatedSQL

@hamsterksu
Copy link
Owner

in this demo app - https://github.com/hamsterksu/annotatedsql_demo
i have query with group by when i calculate comments count.

@SelvinPL
Copy link
Author

what about extras ? CREATE TABLE .... COLUMN1 TEXT COLLATE LOCALIZED

@hamsterksu
Copy link
Owner

what about extras ? CREATE TABLE .... COLUMN1 TEXT COLLATE LOCALIZED

you can use default attribut of Column annotation
@column(type=TEXT, default=" '' COLLATE LOCALIZED")

value of default attirbute will be appended after column type

@SelvinPL
Copy link
Author

there is no default attribute at this moment

@hamsterksu
Copy link
Owner

sorry, my misstake

@Column(type = Type.TEXT, defVal = "'' COLLATE LOCALIZED")

but it will not work :( lib generates sql like

description TEXT DEFAULT ('' COLLATE LOCALIZED))

I will add new attribute collate to the @column.

thanks,

@hamsterksu
Copy link
Owner

one another comment about View and query w/o mapping:
for each view lib generates ViewName2 class with new columns names.
column name will be genarted by the following tempalte:

<table_alias_name>_<column_name>

i did it to prevent ambiguous column error

@SelvinPL
Copy link
Author

yeah, i saw that when i was analyzing generated code :) anyway nice library/generator

hamsterksu added a commit that referenced this issue Oct 25, 2014
@hamsterksu
Copy link
Owner

"extra" attribute was added. version 1.10.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants