How can I type check uuid and date_time in an entity generated from sqlite by sea-orm-cli? - sqlite

I'm using the sea-orm library to manage my database. The uuid() and date_time() types are part of the sea-orm migration syntax. When sea-orm generates the entities from the SQLite database, uuid() and date_time() get converted into String.
Should I change these types on the entities manually for some other type if I want them to be type-checked? How can I do that? What types can I use? Will I have to convert them back to String when importing data into the database? How can I do that?

Related

How can I Store Custom .Net Types in Sqlite Database ?

I want to store my custom types in sqlite database but when i do , it does not create table with an exception. For example, I want to store List in sqlite table, Is there a way to do so ?
I would take a look at SQLite-Net Extensions by TwinCoders.
It can store lists of string and other types by serialising the list. Check this answer for how to store a list of strings.

Microsoft.AspNet.Identity.EntityFramework - UserIdentity and RoleIdenity Id fields

Microsoft.AspNet.Identity.EntityFramework -
Objects UserIdentity and RoleIdenity have Id fields of type string, and thus the tables created have data types nvarchar(128).
Shouldn't these objects Id properties be of type System.Guid and the database have datatypes of uniqueidentifier? Why aren't they? A GUID is inserted on new User and Role creation.
It's most likely because the api is storage provider independent so the kept the field types as generic as possible: http://blogs.msdn.com/b/webdev/archive/2013/06/27/introducing-asp-net-identity-membership-system-for-asp-net-applications.aspx
"If your application requirements are that this information might be stored in a different storage mechanism such as SharePoint, Azure Table Service, No Sql databases etc. it is now possible to plug in different storage providers."
Hao Kung from the ASP.NET team wrote this in a comment on this question on how to change id type to int.
So we decided on string keys to avoid having to deal with key serialization issues, the EF default implementation could have used ints as the primary key, GUIDs were just an easy way to generate a random unique string key.
Another reason for a string user ID may be that strings are hard coded into the claims API, specifically, Microsoft.AspNet.Identity.IdentityExtensions.GetUserId, which uses System.Security.Claims.Value, both of which return strings.

Sqlite C/C++ API - Get timestamp value with select query

I use sqlite3 C/C++ API to retrieve rows from a table using SELECT query. I don't see any sqlite3_column_timestamp() to retrieve a timestamp column value after sqlite3_step().. How to get timestamp values ?
SQLite does not have a special timestamp data type.
When you want to use any of SQLite's date and time functions, you have to store timestamps in one of the formats supported by them, i.e., a string like YYYY-MM-DD HH:MM:SS or HH:MM:SS, a julian date number, or a Unix timestamp number.
You can declare a table column type as DATETIME, but SQLite will just ignore that type; SQLite always allows to put values of any type in any column. Such a declaration would be useful only as documentation.
The column/value accessors will only have types corresponding to the data types they support directly (NULL, INTEGER, REAL, TEXT, BLOB).
You would use the TEXT access to get/set the column value of dates.
There are some helper functions within SQL that they provide that let you to handle them in your queries.
I am not familiar with SQLite Manager, but I would assume that it is only reporting the data type that the table was declared with.
When parsing CREATE statements, sqlite understands the intention of many well supported datatypes and automatically maps them to what is appropriate for its internal storage structure. VARCHAR would be mapped to TEXT, for instance. I assume the column was declared DATETIME and sqlite just internally mapped it to TEXT.

Creating a DateType field on sqlite3

i want to create a table on sqlite with one field as DateTime (YYYY-MM-DD) , how i can create it?
i'm trying with:
create table test (_date datetime);
but i'm not sure if the datatype is correct 'cause i can do this:
create table test (_date nyanType);
and no error occours
SQLite is rather unique in that its columns are not statically typed. You can technically store a string in a column that was created as an integer column.
If you check out the SQlite Documentation for types, you'll see that SQLite dosn't have a date type, but it exposes date and time functions that are suitable for manipulating dates that are stored as TEXT, REAL or INTEGER. You should use those instead.

how to generate a java class code from a sqlite database for ORMLite

Given a sqlite database as input, I want to know how can i can generate an ORMLite java class that map with the associated database. Many thanks.
You could try Telosys Tools, an Eclipse plugin for code generation
working from an existing database with customizable Velocity templates
See: https://sites.google.com/site/telosystools/
A set of templates is available on GitHub for JPA :
//github.com/telosys-tools-community/jpa-templates-TT206-v2
A Java class for JPA is very near to ORMLite so it's possible to adapt the templates
in oder to generate ORMLite java classes
A global tutorial for Spring MVC and JPA :
//sites.google.com/site/telosystutorial/springmvc-jpa-springdatajpa
(you can just consider the JPA bundle)
I am new to ORMLite and also have the same need.
For SQLite, I read and parse the SQL statement in the field "sql" of table "sqlite_master".
Although it works well with tables, I had to find an other way to deal with views; now I use Excel to load data from views into ADO objects and parse fields' properties to generate Java POJO class definition text, then paste it onto IDE.
It's not perfect, saved me a lot of time though.
This is not something that ORMLite can do itself -- you are going to have to help it. If you want to edit your question and include your SQLite schema, I'll edit my answer to include some of the necessary object.
For example, here are some field mappings:
INTEGER -> int
VARCHAR -> String
BOOLEAN -> boolean
TIMESTAMP -> Date
BIGINT -> long
...
I would suggest creating a class and using the TableUtils.getCreateTableStatements(ConnectionSource, Class<T>) method to see what schema is dumped out and how it compares to your existing schema. Then add or modify the fields until you get as close a match as possible.

Resources