Android Question SOLVED Some issue with DBUTILS

Discussion in 'Android Questions' started by tigrot, Feb 10, 2015.

  1. tigrot

    tigrot Well-Known Member Licensed User

    Hi Everybody
    I'm trying to set date('now') using dbutils in a sqllite db.
    I've some problem the date('now') seems to be resolved as string instead of a date function.
    Maybe the issue is the SqlLite itself.
    If I look to the value in datacreazione field i find the litteral Date('now') instead of yyyy-mm-dd...

    Code:
    Dim ListOfMaps As List
            ListOfMaps.Initialize
            
    Dim m As Map
            m.Initialize
            m.Put(
    "Id", Main.codpratica)
            m.Put(
    "cognome", edittext1.text)
            m.Put(
    "nome", edittext2.Text)
            m.Put(
    "tipo",edittext3.text)
            m.Put(
    "tag",edittext4.Text)
            m.Put(
    "datacreazione""Date('now')")
            m.Put(
    "livello",Main.livello)
            m.Put(
    "utente",Main.userx)
            ListOfMaps.Add(m)
            DBUtils.InsertMaps(Main.SQL, 
    "pratiche", ListOfMaps)
    Does anybody have the same problem. I could extract the value for date but this is a too simple workaround!!!

    Grazie a tutti
    Mauro
     
  2. NJDude

    NJDude Expert Licensed User

    It should be:
    Code:
    m.Put("datacreazione"DateTime.Date(DateTime.Now))
     
  3. tigrot

    tigrot Well-Known Member Licensed User

    Thank you very much... Date('now') according to sqllite manual should return date... I'll chose this way "Obtorto collo" !

    Ciao e grazie ancora!
    Mauro
     
  4. NJDude

    NJDude Expert Licensed User

    Prego.
     
  5. keirS

    keirS Well-Known Member Licensed User

    I think it's probably a problem with DBUtils and not SQLite. It's perfectly possible to do an INSERT command with a date function in SQLite. Does your SQLite column have it's affinity set as DateTime or Date?
     
  6. walterf25

    walterf25 Well-Known Member Licensed User

    I agree, most likely the issue is with DBUtils, i've used Date('now') before but without the dbutils and it works fine.

    Cheers,
    Walter
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    DBUtils creates a prepared statement with the values you pass to it. The values will be inserted to the database as is (no need to escape anything). If you need to call a SQL function then you need to create the statement instead of using InsertMaps.
     
  8. tigrot

    tigrot Well-Known Member Licensed User

    I have traced the DBUtils and seems to do the job. The Date('now') function is correctly inserted in INSERT statement. So the issue must be elsewhere... This is not a problem, since I can build the SQL INSERT on my own or pass the date as a value. This is the first time I use SQL Lite, so it's more an exercize for me than a real need. In MsSQL and MySql I use the date function on almost every DB to mark the creation date of each row, for future needs.
    Thank you everybody. You are a high valued group!

    Mauro
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    There is no real issue here. DBUtils, by design, creates an INSERT statement that puts the values as is in the database.
     
  10. tigrot

    tigrot Well-Known Member Licensed User

    Seems that the date('now') is not executed by SQLlite in the format that DBUtils uses for INSERT. Never mind... Just a curiosity.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice