Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data does not appear if fetched from table name with dot symbol #37

Open
rachyharkov opened this issue Aug 3, 2023 · 7 comments
Open
Labels
bug Something isn't working

Comments

@rachyharkov
Copy link

Bug Description

All data from query result wont simply return the all column of the data, resulting only show the data which is came from add() method (but the amount of data is correct).

As my investigation goes, this is caused by table which is placed on different schema (for ex: the data shown up if the table is from "public" schema instead of "other_public" schema)

My Code

In controller

$db = db_connect();
$query = $this->table('other_public.users')

return DataTable::of($builder)
                ->add('my_custom_field', function($row) {
                    return 'some text'
                })
                ->toJson(true);
 

if using model, here is what it looks like:

Model

class Announcement extends Model
{
    protected $DBGroup          = 'default';
    protected $table            = 'cms.announcements';
    protected $primaryKey       = 'id';
    protected $useAutoIncrement = true;
    protected $returnType       = 'object';

}

Controller

class Announcement extends BaseController
{
    protected $announcement_model;

    function __construct()
    {
        $this->announcement_model = new ModelsAnnouncement();
    }

    public function index()
    {
            return DataTable::of($query)
                ->add('my_custom_field', function($row) {
                    return 'some text';
                })
                ->toJson(true);
    }
}

Screenshots
image

but if you check the query result using dd or whatever, it shows all the data

  • PHP Version: 7.4
  • CodeIgniter version: 4.3.6
  • Library version: 0.6.1
@rachyharkov rachyharkov added the bug Something isn't working label Aug 3, 2023
@rachyharkov
Copy link
Author

Looks like the problem come from this function, since the query result shows all the column data

public function getDataResult()

if i change the code like this

public function getDataResult()
{
    $queryResult = $this->queryResult();

    return $queryResult;
}

it shows as expected, but without the value from add, edit, etc.
image

@rachyharkov rachyharkov changed the title [PostgreSQL] Data not showing if fetch from different scheme of database [PostgreSQL] Data does not appear if fetched from table from different schema Aug 3, 2023
@rachyharkov
Copy link
Author

it leads me to this function

public function initFromBuilder($baseBuilder)

on the first conditional, on else block, if the table are from other scheme, the table name have double quotes on each which is separated by dot

image

Here is the result:
image

if i'm changing to table without any schema defined, like this..
image

this is the result:
image

so i'm trying to debug how does getFieldData works since it was a part of Codeigniter 4 it self

public function index()
{
    $db = db_connect();
    $builder = $db->getFieldData('cms.announcements');
    dd($builder);
}

Here is the result...

image

Well, looks like it doesn't need to include the schema name (even with dot, just table name), and here is the result...

public function index()
{
    $db = db_connect();
    $builder = $db->getFieldData('announcements');
    dd($builder);
}

image

@rachyharkov
Copy link
Author

rachyharkov commented Aug 3, 2023

i have proposed the PR #38

@hermawanramadhan
Copy link
Owner

did you try schema on config?
https://codeigniter.com/user_guide/database/configuration.html

I'm worried that if your pull request is applied it will damage other database drivers..

@rachyharkov
Copy link
Author

rachyharkov commented Aug 3, 2023

in my case, i have some connection that depends on other database type (mysqly postgre, and oraclr), i need to still define the dot on option which is required to choose the table by name (especially postgre which is linked to schema)

the code i've applied just doing the general task (detecting dots, if the string are looks normal, just leave it be)

i know that soo many of library user are reliying on mySQL, if they saw the similar problem, they just simply use another lib

honestly, i'm not forcing you to accept my pr, just making use of this lib a bit easier, readable, and understandable, i have spend my time doing the test based on the changes i made, soo i was thinking it's "optionally good" implement those changes

you might need to test it out too

it's interesting to know more about the config, which option that i should set? and what value should i define though?

ps: sorry i'm not on my laptop at the moment right now

@rachyharkov rachyharkov changed the title [PostgreSQL] Data does not appear if fetched from table from different schema Data does not appear if fetched from table name with dot symbol Aug 3, 2023
@hermawanramadhan
Copy link
Owner

I've never tried postgresql

I mean db config whatever on php or .env
Documentation on CodeIgniter you can add schema option on db config

Screenshot 2023-08-03 at 21 02 53 Screenshot 2023-08-03 at 21 01 42 Screenshot 2023-08-03 at 21 01 51

@rachyharkov
Copy link
Author

rachyharkov commented Aug 5, 2023

sorry for having kept you waiting, thanks for suggestion though, i tried tinkering with all of those configuration... nothing met my expectation, the best i can do is modify the base code based on my proposed PR (i was thinking at the beginning, maybe it works because the way of codeigniter is create new connection with new schema, but it fails)

and there's another problem too, while doing search (fetched from non-public schema) the error shown up since the key pressed

i'll try to find what causing this but i'm 100% percent sure the lib base code should handle these behavior might be a good benefit...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants