Laravel overflow when updating value - laravel

The problem I encountered was I have a column named "timeStart" to store the unix epoch time in millisecond. When I was updating through Laravel update function, the value stored in database shows that it's negative instead of the value I wanted it to store.
e.g. value intended to store: 1540090500000
value stored in database: -1802759264
I'm using bigint datatype here. The same code works on my localhost database but not when I uploaded it onto my shared hosting server, which is a weird issue. What can be done to address this issue?

So how can I understod you are using different mysql services .
So to learn more abount 32/64bit based bigint please follow
32/64bit os BIGINT
Also I will suggest you to use string instead of bigint. Some os/operations sometimes conflicts due to type bigint

Related

Laravel 8 and SQL Server: problem with timestamp

Hello everyone and happy new year,
I'm converting my project to use SQL Server instead of MySQL and I'm struggling with the problem of managing timestamps.
In the project, I have this code:
Customers::whereBetween('created_at', [Carbon::now()->subDays('7'), Carbon::now()])->count();
which gives me back the number of new customers registered in the last 7 days.
Using MySQL no problem whatsoever while with SQL Server I get this error:
Converting an nvarchar data type to datetime resulted in a value
outside of the allowable range.
despite in my model, I have set
public function getDateFormat()
{
return 'Y-m-d H: i: s.v';
}
to get the values in milliseconds.
What did I forget to set up?
The error tells you that a conversion failed. Possible reasons:
The date does not exist
If you get February 30th as the input, it will fail.
Input not complying to the format in use
To detect whether this is the problem, you will need to find out what the generated SQL is and find out which value caused this problem. After carefully studying the conversion you should be able to determine what the problem and solution is.

Change column type, Laravel

I have a column $table->date('start_date'); , and I want to store data and time so I will need timestamp.
I already have some date in my current table, so I am not sure what to do without deleting existing data.
I find some solutions (on changing data type) that involve doctrine, but from what I read, Supported Laravel Versions is 6.x and I am using 7.
Any solutions?
According to the PostgreSQL documentation you can convert a date to timestamp by using to_timestamp() function
https://www.postgresql.org/docs/8.2/functions-formatting.html
You have two choices :
Create a new column and create a script which convert all entries in the right format
Create a script which update all the datas you need to into the already existing table

LaraAdmin how to use bigint field type

I'm building some application based on LaraAdmin crud generator. I need a field to be a BigInt since the possible values are bigger than a normal Integer. How should I achieve that in order to not make the system crash?
Because it is stored already as an integer, simply change the database type to biginteger and it'll be fine as they both store numerical values.

Enterprise Architect Oracle long field column properties

I have a little problem with Enterprise Architect by Sparx System.
Im trying to model database schema for Oracle. I created table with primary key with data type long. But when im trying to modify column properties (set AutoNum = true) I see empty properties. I read documentation of EA and saw that I need to setup this property to generate sequence syntax.
When I change data type to number, or switch database to mysql (for example) everything is alright, there are properties so Im able to modify AutoNum value.
Did you had similar problem and found solution ? or maybe im doing something wrong.
regards
It's becouse Oracle use sequence instead of autoincrement option. I've checked it and I think you have to use NUMBER column type and then set AutoNum property (you have to select Generate Sequences in options to get proper DDL code too). Instead of LONG data type you can set PRECISION and SCALE options on NUMBER type ie NUMBER(8) mean you can have 8 digits number and it can be set up to 38, so if you don't want to store info about every star in the universe will be enought for your scenario :)

How should I use UUID with JavaDB/Derby and JDBC?

I currently use INT as type for primary key in JavaDB (Apache Derby), but since I'm implementing an distributed system I would like to change the type to java.util.UUID. A few questions about this:
What datatype in JavaDB/Derby should I use for UUID? I have seen CHAR(16) FOR BIT DATA been mentioned but I don't know much about it. Is VARCHAR(16) an alternative?
How should I use it with JDBC? E.g. in an PreparedStatement, how should I set and get an UUID?
If I later would likte to change database to SQL Server, is there a compatible datatype to java.util.UUID?
Simply, How should I use UUID with JavaDB/Derby and JDBC?
UUID is a 128 bit value. The CHAR(16) FOR BIT DATA type reflects that it is bit data stored in character form for conciseness. I don't think VARCHAR(16) would work because it doesn't have the bit flag. The database would have to be able to convert the binary data to character data which deals with encoding and is risky. More importantly, it wouldn't buy you anything. Since a UUID is always 128 bits, you don't get the space savings from using VARCHAR over CHAR. So you might as well use the intended CHAR(16) FOR BIT DATA.
With JDBC, I think you use the get/setBytes() method since it is dealing with small amounts of binary data. (Not positive, would have to try this)
And no idea about the SQL Server part.
If you still want to use the UUID object in your code you can use fromString to create UUID objects from the DB and toString to store them in the DB.
You could convert the UUID to a string and store it as VARCHAR. Most UUID string formats are similar to this one: 32 digits separated by hyphens: 00000000-0000-0000-0000-000000000000, so then you'd want a VARCHAR(36), or make it something like VARCHAR(64) if you please, since it doesn't hurt to have extra 'space' available in your VARCHAR -- only the actual digits are stored.
Once you've converted it to a string, just call Statement.SetString to include it in your INSERT statement.

Resources