Jump to content

Big Numbers, when integer is not enough. What to do?


bobbit6k
 Share

Recommended Posts

Hi @bobbit6k

Welcome to the forums :)

MySQL INT (unsigned) can store up to 4.2 billion. I think ProcessWire uses signed INT for integer fields, so, you get about 2.1 billion. If you need something bigger, there is MySQL BIGINT. If you need to manipulate the data as numbers, one solution  is to create your own custom Fieldtype that extends FieldtypeInteger and uses BIGINT in its database schema. We can show you how if you wish...Otherwise, if you just need a "number", you can go with a text field.

FYI

https://dev.mysql.com/doc/refman/5.7/en/integer-types.html

https://planet.mysql.com/entry/?id=13825

 

 

 

Edited by kongondo
  • Like 3
Link to comment
Share on other sites

Storing it as text is fine if you're not performing numeric operations on DB,

But you can copy /wire/modules/Fieldtype/FieldtypeInteger.module to /site/modules and open up the file, find and change getDatabaseSchema() from

public function getDatabaseSchema(Field $field) {
    $schema = parent::getDatabaseSchema($field);
    $schema['data'] = 'int NOT NULL';
    return $schema;
}

to

public function getDatabaseSchema(Field $field) {
    $schema = parent::getDatabaseSchema($field);
    $schema['data'] = 'BIGINT NOT NULL';
    return $schema;
}

Once you refresh module list from Modules > Refresh, it'll ask you which version to use, pick the one under /site/modules

image.png.7e252739c17fcf60ac01f40ac635cbdf.png

Then create a new integer field, it will be set up as BIGINT in DB.

  • Like 2
Link to comment
Share on other sites

46 minutes ago, abdus said:

Storing it as text is fine if you're not performing numeric operations on DB,

But you can copy /wire/modules/Fieldtype/FieldtypeInteger.module to /site/modules and open up the file, find and change getDatabaseSchema() from


public function getDatabaseSchema(Field $field) {
    $schema = parent::getDatabaseSchema($field);
    $schema['data'] = 'int NOT NULL';
    return $schema;
}

to


public function getDatabaseSchema(Field $field) {
    $schema = parent::getDatabaseSchema($field);
    $schema['data'] = 'BIGINT NOT NULL';
    return $schema;
}

Once you refresh module list from Modules > Refresh, it'll ask you which version to use, pick the one under /site/modules

image.png.7e252739c17fcf60ac01f40ac635cbdf.png

Then create a new integer field, it will be set up as BIGINT in DB.

Very Very Nice and quick!

Thanks Man!

  • Like 1
Link to comment
Share on other sites

4 hours ago, abdus said:

But you can copy /wire/modules/Fieldtype/FieldtypeInteger.module to /site/modules and open up the file, find and change getDatabaseSchema()

I think there will be a bit more to it than this, because there are quite a few places in FieldtypeInteger and InputfieldInteger where the value is cast with (int), which will truncate the value of high integers depending on platform.

https://stackoverflow.com/questions/670662/whats-the-maximum-size-for-an-int-in-php/2842548#2842548

 

2 hours ago, szabesz said:

Another option might be the FieldtypeDecimal module

This one works well.

  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...