AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Datenbanken Delphi Feld 'Datum' kann nicht als Typ DateTime angesprochen werden.
Thema durchsuchen
Ansicht
Themen-Optionen

Feld 'Datum' kann nicht als Typ DateTime angesprochen werden.

Ein Thema von Devil1925 · begonnen am 21. Sep 2016 · letzter Beitrag vom 21. Sep 2016
Antwort Antwort
Benutzerbild von Devil1925
Devil1925

Registriert seit: 20. Nov 2015
Ort: Saerbeck
236 Beiträge
 
Delphi 10.3 Rio
 
#1

Feld 'Datum' kann nicht als Typ DateTime angesprochen werden.

  Alt 21. Sep 2016, 11:16
Datenbank: SQLITE • Version: ??? • Zugriff über: uniDAC
Moin Leute, ich habe folgendes Problem:

Ich mache eine SQL-Abfrage auf eine SQLITE - Datenbank

Code:
Select Erstellt as Datum, ID from Tabelle
UNION
Select datetime('now', 'localtime') as Datum, id from Tabelle2
Erstellt ist vom Typ DateTime, ID vom Typ Integer

nun möchte ich über

Delphi-Quellcode:

Quey1.FieldByname('Datum').AsDatetime
auf das Feld zugreifen. allerdings wird mir hier immer die Fehlermeldung
Code:
Feld 'Datum' kann nicht als Typ DateTime angesprochen werden.
ausgegeben.

Hat hier jemand eine zündende Idee?

Vielen Dank schonmal im Vorraus!
Philipp
Höllische Grüße
Devil
Meistens sitzt das Problem vor dem Bildschirm! - Leider bin das oftmals ich.
  Mit Zitat antworten Zitat
Benutzerbild von MrSpock
MrSpock
(Co-Admin)

Registriert seit: 7. Jun 2002
Ort: Owingen
5.865 Beiträge
 
Delphi 2010 Professional
 
#2

AW: Feld 'Datum' kann nicht als Typ DateTime angesprochen werden.

  Alt 21. Sep 2016, 11:40
Habe noch nicht mit SQLITE gearbeitet, aver gerade mal nachgeschaut. Die Funktion datetime liefert einen String zurück. Grundsätzlich könnte man den Typ mit CAST in der SQL Abfrage umwandel, aber ich habe keinen Datumstyp in SQLITE gefunden.

Bleibt wohl nur die Umwandlung in Delphi von String in DateTime.
Albert
Live long and prosper


MrSpock
  Mit Zitat antworten Zitat
Benutzerbild von Stevie
Stevie

Registriert seit: 12. Aug 2003
Ort: Soest
4.008 Beiträge
 
Delphi 10.1 Berlin Enterprise
 
#3

AW: Feld 'Datum' kann nicht als Typ DateTime angesprochen werden.

  Alt 21. Sep 2016, 11:50
Quey1.FieldByname('Datum').DataType = ?
Stefan
“Simplicity, carried to the extreme, becomes elegance.” Jon Franklin

Delphi Sorcery - DSharp - Spring4D - TestInsight
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu
Online

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.136 Beiträge
 
Delphi 12 Athens
 
#4

AW: Feld 'Datum' kann nicht als Typ DateTime angesprochen werden.

  Alt 21. Sep 2016, 12:17
SQLite kennt keine Zeit-Typen (praktisch ... nutze kein SQLite, aber hab das grade erst vor Kurzem gelernt )

Bezüglich TDateTime muß der String im lokalen Datumsformat vorlitextegen, oder als Float (der interne TDateTime-Typ) oder Integer aus der Datenbank kommen, damit AsDateTime das umwandeln kann. (das automatische Umwandeln passiert dabei im Client, daher auch das lokale Datumsformat, beim String)

SQLite kennt nur TEXT, NUMERIC, INTEGER, REAL und BLOB und und versucht alle anderen Typen darauf abzubilden.
Alles, was es nicht zuordnen kann, wird als TEXT NUMERIC behandelt.
https://www.sqlite.org/datatype3.html
http://perfect-knowhow.de/best-pract...-type-affinity
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests

Geändert von himitsu (21. Sep 2016 um 13:40 Uhr)
  Mit Zitat antworten Zitat
Benutzerbild von Stevie
Stevie

Registriert seit: 12. Aug 2003
Ort: Soest
4.008 Beiträge
 
Delphi 10.1 Berlin Enterprise
 
#5

AW: Feld 'Datum' kann nicht als Typ DateTime angesprochen werden.

  Alt 21. Sep 2016, 12:29
How does UniDAC handle SQLite DateTime fields?
Stefan
“Simplicity, carried to the extreme, becomes elegance.” Jon Franklin

Delphi Sorcery - DSharp - Spring4D - TestInsight
  Mit Zitat antworten Zitat
Aviator

Registriert seit: 3. Jun 2010
1.610 Beiträge
 
Delphi 10.3 Rio
 
#6

AW: Feld 'Datum' kann nicht als Typ DateTime angesprochen werden.

  Alt 21. Sep 2016, 13:31
Alles, was es nicht zuordnen kann, wird als TEXT behandelt.
Das ist so nicht richtig. Die Erkennung des Datentyps wird nach einem festen Schema abgearbeitet. Trifft keine Regeln zu, dann ist der Datentyp Numeric.

Zitat von SQLite Documentation:
3.1. Determination Of Column Affinity
The affinity of a column is determined by the declared type of the column, according to the following rules in the order shown:
  1. If the declared type contains the string "INT" then it is assigned INTEGER affinity.
  2. If the declared type of the column contains any of the strings "CHAR", "CLOB", or "TEXT" then that column has TEXT affinity. Notice that the type VARCHAR contains the string "CHAR" and is thus assigned TEXT affinity.
  3. If the declared type for a column contains the string "BLOB" or if no type is specified then the column has affinity BLOB.
  4. If the declared type for a column contains any of the strings "REAL", "FLOA", or "DOUB" then the column has REAL affinity.
  5. Otherwise, the affinity is NUMERIC.

Note that the order of the rules for determining column affinity is important. A column whose declared type is "CHARINT" will match both rules 1 and 2 but the first rule takes precedence and so the column affinity will be INTEGER.
Quelle: https://www.sqlite.org/datatype3.htm...olumn_affinity
  Mit Zitat antworten Zitat
Benutzerbild von DeddyH
DeddyH

Registriert seit: 17. Sep 2006
Ort: Barchfeld
27.540 Beiträge
 
Delphi 11 Alexandria
 
#7

AW: Feld 'Datum' kann nicht als Typ DateTime angesprochen werden.

  Alt 21. Sep 2016, 13:35
Und ergänzend dazu:
Zitat:
2.2. Date and Time Datatype

SQLite does not have a storage class set aside for storing dates and/or times. Instead, the built-in Date And Time Functions of SQLite are capable of storing dates and times as TEXT, REAL, or INTEGER values:

TEXT as ISO8601 strings ("YYYY-MM-DD HH:MM:SS.SSS").
REAL as Julian day numbers, the number of days since noon in Greenwich on November 24, 4714 B.C. according to the proleptic Gregorian calendar.
INTEGER as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC.
Applications can chose to store dates and times in any of these formats and freely convert between formats using the built-in date and time functions.
Detlef
"Ich habe Angst vor dem Tag, an dem die Technologie unsere menschlichen Interaktionen übertrumpft. Die Welt wird eine Generation von Idioten bekommen." (Albert Einstein)
Dieser Tag ist längst gekommen
  Mit Zitat antworten Zitat
Benutzerbild von Devil1925
Devil1925

Registriert seit: 20. Nov 2015
Ort: Saerbeck
236 Beiträge
 
Delphi 10.3 Rio
 
#8

AW: Feld 'Datum' kann nicht als Typ DateTime angesprochen werden.

  Alt 21. Sep 2016, 14:20
Vielen Dank! Ihr habt mir viel weiter geholfen! jetzt funktioniert alles!
Philipp
Höllische Grüße
Devil
Meistens sitzt das Problem vor dem Bildschirm! - Leider bin das oftmals ich.
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 20:20 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz