Advertisement:

Author Topic: create_table unsigned  (Read 2996 times)

Offline inter

  • Jr. Member
  • **
  • Posts: 276
  • Gender: Male
    • interlab on GitHub
create_table unsigned
« on: April 11, 2017, 05:16:20 AM »
SMF 2.0.13
php 5.6.30
mysql 5.7.12-log

Docs: http://wiki.simplemachines.org/smf/$smcFunc#db_create_table

Code: [Select]
// test
$columns = [
    [
        'name' => 'port',
        'type' => 'smallint',
        'size' => 5,
        'unsigned' => true,
        'null' => false,
        'default' => 0,
    ]
];
$indexes = [
    [
        'type' => 'index',
        'columns' => ['port'],
    ],
];
$smcFunc['db_create_table']('{db_prefix}_bug_test', $columns, $indexes, [], 'ignore');


offtop: how to set engine InnoDB for table with $smcFunc? set foreign key with $smcFunc?
Sorry for my English

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 67,343
    • Arantor on GitHub
Re: create_table unsigned
« Reply #1 on: April 11, 2017, 05:18:23 AM »
Version of SMF?

There is no way to explicitly set InnoDB or foreign keys owing to the abstraction layer. You could just write the queries yourself and tell it to use the security override instead.
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

You either die a hero or live long enough to see yourself become the villain. It seems you have chosen which, and now I must do the same.

Offline inter

  • Jr. Member
  • **
  • Posts: 276
  • Gender: Male
    • interlab on GitHub
Re: create_table unsigned
« Reply #2 on: April 11, 2017, 05:21:11 AM »
SMF 2.0.13
php 5.6.30
mysql 5.7.12-log



Solution:

file: .../Sources/DbPackages-mysql.php

find:
Code: [Select]
$unsigned = in_array($type, array('int', 'tinyint', 'smallint', 'mediumint', 'bigint', 'float')) && !empty($column_info['unsigned']) ? 'unsigned ' : '';
replace:
Code: [Select]
$unsigned = in_array($type, array('int', 'tinyint', 'smallint', 'mediumint', 'bigint', 'float')) && !empty($column['unsigned']) ? 'unsigned ' : '';
« Last Edit: April 11, 2017, 06:12:52 AM by inter »
Sorry for my English

Offline albertlast

  • Development Contributor
  • Jr. Member
  • *
  • Posts: 124
Re: create_table unsigned
« Reply #3 on: May 17, 2017, 04:58:45 PM »
size 5 make no sense in this context,
please keep this information empty.

Offline inter

  • Jr. Member
  • **
  • Posts: 276
  • Gender: Male
    • interlab on GitHub
Sorry for my English