Autore Topic: Set own date to mysql table  (Letto 657 volte)

Offline eloaders

  • Gamberetto
  • *
  • Post: 38
    • Mostra profilo
Set own date to mysql table
« il: 02 Febbraio 2017, 00:07:56 »
I have the code, however, the matter is simple. I have a page editing post, to decide the date of publication. However, gambas returns me an error.

Codice: [Seleziona]
' Gambas class file

Public rPosts As Result
Public Sub _new()
  Dim POSTDATE As String
  'Print Request.Post["post_date"] & " " & Request.Post["post_time"]
  If Request.Method = "POST" Then
    If IsInteger(Request.Post["post_id"]) Then
      rPosts = DB.Edit("posts", " id = &1", Request.Post["post_id"])
      If MFunctions.IsMimeType(Request.Files["post_image"], "image/png") = True Then
        If Request.Post.Exist("post_image") = True Then
          Try Copy Request.Post.Files["post_image"] To "" & Application.Path & "/Uploads/Images/" & Request.Post["post_image"] & "" & ""
          rPosts!post_image = "/Uploads/Images/" & Request.Post["post_image"]
        Endif
      Endif
      rPosts!post_title = Request.Post["post_title"]
      rPosts!post_content = Request.Post["post_content"]
      rPosts!post_tags = Request.Post["post_tags"]
      rPosts!post_name = Request.Post["post_name"]
      rPosts!post_author = Request.Post["post_author"]
      Print Now
      POSTDATE = URL.UnQuote(Replace(Request.Post["post_date"], "\n", ""))
      'Print CFloat(Val(Request.Post["post_date"]))
      'Print URL.UnQuote(Request.Post["post_date"])
      'Print CDate(CInteger(Replace(Request.Post["post_date"], ".", "") & Replace(Request.Post["post_time"], ":", "")))
      rPosts!post_date = POSTDATE
      rPosts!post_type = Request.Post["post_type"]
      rPosts!post_status = Request.Post["post_status"]
      rPosts.Update
     
    Else If Request.Post["post_id"] = "new" Then
      rPosts = DB.Create("posts")
     
      If Request.Post.Exist("post_image") = True Then
        If MFunctions.IsMimeType(Request.Files["post_image"], "image/png") = True Then
          Try Copy Request.Post.Files["post_image"] To "" & Application.Path & "/Uploads/Images/" & Request.Post["post_image"] & "" & ""
          rPosts!post_image = "/Uploads/Images/" & Request.Post["post_image"]
          rPosts!post_image_alt = Request.Post["post_image"]
        Endif
      Endif
      rPosts!post_title = Request.Post["post_title"]
      rPosts!post_content = Request.Post["post_content"]
      rPosts!post_tags = Request.Post["post_tags"]
      rPosts!post_name = Request.Post["post_name"]
      rPosts!post_author = Request.Post["post_author"]
      'rPosts!post_date = Now
      'rPosts!post_date = Request.Post["post_date"] & " " & Request.Post["post_time"]
      rPosts!post_type = Request.Post["post_type"]
      rPosts!post_status = Request.Post["post_status"]
      rPosts.Update
    Endif
  Endif
 
  If Request.Method = "GET" Then
    If Request.Get["action"] = "delete" Then
      DB.Delete("posts", "ID = &1", Request.Get["id"])
    Endif
   
  Endif
 
End


I'm talking about: rPosts!post_date = POSTDATE

type of table post_date is datetime with default values CURRENT_TIMESTAMP   ON UPDATE CURRENT_TIMESTAMP
« Ultima modifica: 02 Febbraio 2017, 00:09:25 da eloaders »

Offline Gianluigi

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 4.243
  • Tonno verde
    • Mostra profilo
Re:Set own date to mysql table
« Risposta #1 il: 02 Febbraio 2017, 22:44:55 »
Hi Eloaders,
some questions:

How you connect to the database?
What is the Request? It is an object of Gambas? What component must be activated?
What kind of data contains MySql?
You can attach your project?

 :ciao:
nuoto in attesa del bacio di una principessa che mi trasformi in un gambero azzurro

Offline eloaders

  • Gamberetto
  • *
  • Post: 38
    • Mostra profilo
Re:Set own date to mysql table
« Risposta #2 il: 02 Febbraio 2017, 23:23:57 »
The project is called CERBERO and sources are available here

https://github.com/i-nex/Cerbero/blob/master/.src/Admin/Writer/WWriter.class

You can view the files, only problem I have with setting the date for the blog entry.




Offline Gianluigi

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 4.243
  • Tonno verde
    • Mostra profilo
Re:Set own date to mysql table
« Risposta #3 il: 03 Febbraio 2017, 09:49:30 »
Hi Eloaders,

unfortunately neither I, nor the friend to whom I asked, we can help.
The only thing we can do is congratulate with you for the excellent work.
I hope someone able to help throws your eye on this topic and answer thee.
 :(
« Ultima modifica: 03 Febbraio 2017, 10:24:55 da Gianluigi »
nuoto in attesa del bacio di una principessa che mi trasformi in un gambero azzurro

Offline eloaders

  • Gamberetto
  • *
  • Post: 38
    • Mostra profilo
Re:Set own date to mysql table
« Risposta #4 il: 05 Febbraio 2017, 11:50:14 »
In short, I have a problem with that
I think that now it is more understandable

Codice: [Seleziona]
Dim rPosts As Result
rPosts = DB.Edit("posts", " id = &1", Request.Post["post_id"])
rPosts!post_date = "2017-02-04 10:20:51"
rPosts.Update

rPosts!post_date is a datetime, if i set as TEXT then it works.

The code below works correctly
Codice: [Seleziona]
Dim rPosts As Result
rPosts = DB.Edit("posts", " id = &1", Request.Post["post_id"])
rPosts!post_date = Now
rPosts.Update
« Ultima modifica: 05 Febbraio 2017, 12:03:33 da eloaders »

Offline Gianluigi

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 4.243
  • Tonno verde
    • Mostra profilo
Re:Set own date to mysql table
« Risposta #5 il: 05 Febbraio 2017, 14:21:59 »
If it works well with:
Codice: [Seleziona]
rPosts!post_date = Now
then try to insert the date like this:
Codice: [Seleziona]
rPosts!post_date = Date(2017, 02, 04, 10, 20, 51)
nuoto in attesa del bacio di una principessa che mi trasformi in un gambero azzurro

Offline eloaders

  • Gamberetto
  • *
  • Post: 38
    • Mostra profilo
Re:Set own date to mysql table
« Risposta #6 il: 05 Febbraio 2017, 16:10:01 »
Ok, it works but.

if i set

Codice: [Seleziona]
Print CDate("" & Request.Post["post_date"] & "")

or

Codice: [Seleziona]
Print CDate(Request.Post["post_date"])

Return me

Type mismatch: wanted Date, got String instead   6

Where Request.Post["post_date"] = 2017/02/05 14:04:45

Offline eloaders

  • Gamberetto
  • *
  • Post: 38
    • Mostra profilo
Re:Set own date to mysql table
« Risposta #7 il: 05 Febbraio 2017, 16:30:03 »
I found a solution to the problem, but I will explain it later

Offline Gianluigi

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 4.243
  • Tonno verde
    • Mostra profilo
Re:Set own date to mysql table
« Risposta #8 il: 09 Febbraio 2017, 07:32:48 »
Our friend Tornu made a small example on inserting and reading in MySql data of type Time, Date, and DateTime.
You can download it from here.
nuoto in attesa del bacio di una principessa che mi trasformi in un gambero azzurro