Welcome Guest, Not a member yet? Register   Sign In
Shield with Oracle - get date format error
#1

I'm trying to test Shield with an oracle database. I was able to install it. I'm able to bring up the login and register views. When I submit the form to register a user I get:
"CodeIgniter\Database\Exceptions\DatabaseException: oci_execute(): ORA-01861: literal does not match format string"
This seems to be caused by the attempt to insert dates for 'created_at' and 'inserted_at' etc. I tried monkeying with the date string that's returned in \vendor\codeigniter4\framework\system\BaseModel.php. If I have it return null for the date then an insertion is made in the 'users' table, but the 'format string' error is still thrown. When I try to log in using the credentials I submitted I get the same 'format string' error, and get the 'Whoops' view. 
This is the version of Oracle I'm using:

"Oracle Database 19c Standard Edition 2 Release 19.0.0.0.0 - Production
Version 19.21.0.0.0"

Any help would be greatly appreciated!! I was asked to evaluate whether or not Shield is an opion for the government agency I'm consulting for and I've had to tell them that it just doesn't work but that I'll see if I can get some support and will get back to them.

Thanks in advance!!
-Jeremy
Reply
#2

(This post was last modified: 11-14-2023, 01:07 AM by kenjis.)

Check "ORA-01861". This is an error due to a different date format.
Shield uses the date "YYYYY-MM-DD HH:MM:SS".

See also https://github.com/codeigniter4/shield/issues/608
Reply
#3

(This post was last modified: 11-14-2023, 08:09 AM by [email protected].)

Thank you so much for your reply! It turns out that I was very confused because I had assumed I should be able to create a user by accessing the register path right out of the box. I'm an old-school developer, so I'm still getting used to the fact that the vendor directory can be like a hall of mirrors, and that there are routes can point to controllers, methods, and views, regardless of not being defined in config/routes,. The confusing thing is that right out of the box it's possible to bring up a login view by simply appending '/login' to the url, and you appear to be able to create a user by clicking the 'register' link there, but this is not how it's meant to be used. It's like trying to email your parents on the cardboard computer at the furniture store, only for some reason the cardboard computer actually powers on and lets you open gmail.

I subsequently understood that I can create users via the command line, which I have now done successfully, and that I need to build my application properly, in the 'app' directory, extending the built in classes, rather than trying to make use of the half baked application code that's crammed like yardgoods into the vendor folder. Maybe I'm just too old for this :-D

I think the moral of the story is that I should always ignore the vendor folder, like the dirty white van next to the school yard. Also, my first computer had a 20 megabyte hard drive, and my test app here is over 25 megabytes though I have not yet written a single line of code. I just have to stop fighting it. The world has moved on and I am getting old!

UPDATE: I will tell the agency I'm working for that I was being a dummy, that there's nothing wrong with CodeIgniter Shield, and they will have a good laugh at my expense. And I will tell them that I got a helpful reply from CodeIgniter support, so thanks again!
Reply
#4

(This post was last modified: 11-15-2023, 03:27 PM by [email protected].)

Just to help out anyone who might be having trouble with their date formats: Once I got past my confusion, as mentioned above, it turned out that I did still have a date format issue. What it comes down to is that if your database is configured in such a way that it won't accept a datetime in the format Y-m-d H:iConfused then you will get an error with Shield simply because Shield extends CI4 BaseModel for inserting and updating data, and the CI4 BaseModel methods 'timeToDate' and 'intToDate' assert the datetime format as Y-m-d H:iConfused'

In order to override these methods, you can create a UserModel in your app directory that extends Shield's UserModel (class UserModel extends \CodeIgniter\Shield\Models\UserModel) containing only the 'timeToDate' and 'intToDate' methods, using whatever date formats you need. You'll also want to include Shield's 'updateActiveDate' method to use the same custom date format. Since this model will only contain these 3 methods, it's no big deal to set your custom date format into each one, but for a more elegant solution you can set your date format into a config file and have your 3 methods reference that, so you'd only have to specify it once.

Then go to App/Controllers/AuthController.php and replace 'use CodeIgniter\Shield\Models\UserModel;' with 'use App\Models\UserModel;' This will override the three methods mentioned above, preserving everything else as is. This approach saves you from having to change any files in your vendor folder, which you want to avoid because such changes would be lost when you do a Composer update.

This has enabled me to register new users without hitting the date format error. I don't know if there are other instances in Shield that will run into this date format problem, but I assume they could be fixed by continuing along the lines of the above approach.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB