Retrieve a list of date from a SQL query - list

Is it possible to retrieve a List<Date> instead of a List<SomeBean> using Ebean ?
For example, I have this model:
Days(id, name, day);
I'd like to do something like:
List<Date> dates = Ebean.createQuery(Date.class, "SELECT day FROM days").findList();
Of course, this doesn't work and returns this:
PersistenceException: java.util.Date is NOT an Entity Bean registered with this server?
How can I do that?

you can use sqlQuery see SqlQuery in Ebean :
The database retrieves time and date data with a type LocalDateTime
String sql = "select day from days";
List<SqlRow> row = DB.sqlQuery(sql).findList();
List<LocalDateTime> days = row.stream().map(r->(LocalDateTime) r.get("day")).collect(Collectors.toList());

Related

Netsuite suiteql how to get all available tables to query?

I am using Postman and Netsuite's SuiteQL to query some tables. I would like to write two queries. One is to return all items (fulfillment items) for a given sales order. Two is to return all sales orders that contain a given item. I am not sure what tables to use.
The sales order I can return from something like this.
"q": "SELECT * FROM transaction WHERE Type = 'SalesOrd' and id = '12345'"
The item I can get from this.
"q": "SELECT * FROM item WHERE id = 1122"
I can join transactions and transactionline for the sale order, but no items.
"q": "SELECT * from transactionline tl join transaction t on tl.transaction = t.id where t.id in ('12345')"
The best reference I have found is the Analytics Browser, https://system.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2021_1/analytics/record/transaction.html, but it does not show relationships like an ERD diagram.
What tables do I need to join to say, given this item id 1122, return me all sales orders (transactions) that have this item?
You are looking for TransactionLine.item. That will allow you to query transaction lines whose item is whatever internal id you specify.
{
"q": "SELECT Transaction.ID FROM Transaction INNER JOIN TransactionLine ON TransactionLine.Transaction = Transaction.ID WHERE type = 'SalesOrd' AND TransactionLine.item = 1122"
}
If you are serious about getting all available tables to query take a look at the metadata catalog. It's not technically meant to be used for learning SuiteQL (supposed to make the normal API Calls easier to navigate), but I've found the catalog endpoints are the same as the SuiteQL tables for the most part.
https://{{YOUR_ACCOUNT_ID}}.suitetalk.api.netsuite.com/services/rest/record/v1/metadata-catalog/
Headers:
Accept application/schema+json
You can review all the available records, fields and joins in the Record Catalog page (Customization > Record Catalog).

Django How to select differrnt table based on input?

I have searched for the solution to this problem for a long time, but I haven't got the appropriate method.
Basically All I have is tons of tables, and I want to query value from different tables using raw SQL.
In Django, we need a class representing a table to perform the query, for example:
Routes.objects.raw("SELECT * FROM routes")
In this way, I can only query a table, but what if I want to query different tables based on the user's input?
I'm new to Django, back in ASP.NET we can simply do the following query:
string query = "SELECT * FROM " + county + " ;";
var bus = _context.Database.SqlQuery<keelung>(query).ToList();
Is this case, I can do the query directly on the database instead of the model class, and I can select the table based on the user's selection.
Is there any method to achieve this with Django?
You can run raw queries in Django like this -
From django.db import connection
cursor = connection.cursor()
table = my_table;
cursor.execute("Select * from " + table)
data = cursor.fetchall()

Query records which are greater than today's date using cqlengine

I want to query a record which are having today's date. The cql code am trying is given below
cron = Cron.objects.filter(user_id = 5)
cron= cron.filter(created_at__gte = datetime.combine(datetime.now().date(), datetime.min.time()))
cron= cron.allow_filtering()
result = cron.first()
I don't have today's record in the table, still am getting the record which are of yesterday in the query result.
Format of date in table is '2015-10-21 08:29:41-0400' (timestamp).
I don't find any reference for this case in cqlengine documents. If anyone can help that you would be great.
In Cassandra you can not where bind or filter whatever you want there has some restriction in cassandra you query in a sequence order first partition key then clustering key.
you can query greater than today if your clustering key is timeuuid, deateime or date filed.
class Blog(Model):
content_type = Text(partition_key=True)
content_id = Date(primary_key=True)
query=Blog.object(content_type='article' and content_id__gte=datetime.now().date())
you can try this way

Inserting date/timestamp values into SQL Server table using Python

I have three variables stored as number, string and string, as shown below.
load_id = 100
t_date = '2014-06-18'
p_date = '19-JUN-14 10.51.45.378196'
I would like to insert them into a SQL Server table using Python 2.7. The SQL Server table structure is as follows
load_id = float
t_date = date
p_date = timestamp
In Oracle, we tend to use TO_DATE or TO_TIMESTAMP to convert the string to DATE or TIMESTAMP field.
I would like to know how I can do similar conversion while inserting into an SQL Server table.
Thanks in advance.
convert with :
import datetime
import calendar
thedate=datetime.datetime.strptime(p_date,'%d-%b-%y %H.%M.%S.%f')
thetimestamp=calendar.timegm(thedate.utctimetuple())
https://community.toadworld.com/platforms/sql-server/b/weblog/archive/2012/04/18/convert-datetime-to-timestamp
DECLARE #DateTimeVariable DATETIME
SELECT #DateTimeVariable = GETDATE()
SELECT #DateTimeVariable AS DateTimeValue,
CAST(#DateTimeVariable AS TIMESTAMP) AS DateTimeConvertedToTimestampCAST
SELECT CAST(CAST(#DateTimeVariable AS TIMESTAMP) AS DATETIME) AS
TimestampToDatetime
Do the conversion with SQL instead of trying to get Python to match the SQL format.
Neither format matches yours, however the DATETIME type should be adequate.

how to get the date from a datetime register in doctrine?

im using codeigniter with doctrine, this is my bd:
id fecha_publicacion
1 2013-03-23 14:52:06
2 2013-03-23 18:02:06
3 2013-03-23 00:00:00
.. ...
what i want to do, is to search those publications from a certain date or between a certain range of dates
The thing is that, if i want to select all those fields with the date 2013-03-23 my query only returns the 3erd field (which time is 00:00:00)
how can i do to get what i want? i've tried many things but had no success
public function postsByDates($tipo,$fecha1,$fecha2=''){
if($fecha2 == ''){
$fecha2 = $fecha1;
}
$this->qb = $this->em->createQueryBuilder();
$this->qb->select('p')
->from('models\Post', 'p')
->where(
$this->qb->expr()->eq('p.tipo', '?1'),
$this->qb->expr()->between('p.fecha_publicacion', '?2', '?3')
)
->setParameter(1, $tipo)
->setParameter(2, "$fecha1%")
->setParameter(3, "$fecha2%");
$query = $this->qb->getQuery();
$obj = $query->getResult();
return $obj;
}
The problem is you are supplying a date for a datetime/timestamp comparison. So I am guessing it converts your supplied date (2013-03-23) to a timestamp (2013-3-23 00:00:00).
Quick fix: You can have the two dates like "2013-03-23 00:00:00" and "2013-03-23 23:59:59".
Good solution: You DQL native query to call MySQL's date() function to convert your timestamp field (fecha_publicacion) to date. After that you will be able to use the between function.