irsyadulibad / ci4-datatables

Server Side Datatables Library for CodeIgniter 4 Framework
https://ci4-datatables.netlify.app
MIT License
72 stars 32 forks source link

Gabisa select concat #18

Open dens4t opened 2 years ago

dens4t commented 2 years ago

Kodingan saya untuk select concat yaitu

return DataTables::use('tb_kelas')
        ->select("id, CONCAT(tingkat, abjad) as kelas")
        ->addColumn('action', function($data) {
            return "<a href=\"" . base_url('Kelas/'. $data->id . "/ubah")."\" class=\"btn btn-sm btn-success mr-1\"><i class=\"fas fa-edit\"></i> Ubah</a>
            <a href=\"#\" onclick=\"konfirmasiHapus(" . $data->id .")\" class=\"btn btn-sm btn-danger\"><i class=\"fas fa-trash\"></i> Hapus</a>";
        })->rawColumns(['action'])
        ->make(true);

dan untuk isian columns datatable di halaman frontendnya yaitu id dan kelas

error yang didapatkan

{
    "title": "mysqli_sql_exception",
    "type": "mysqli_sql_exception",
    "code": 500,
    "message": "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 5",
    "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\Database\\MySQLi\\Connection.php",
    "line": 292,
    "trace": [
        {
            "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\Database\\MySQLi\\Connection.php",
            "line": 292,
            "function": "query",
            "class": "mysqli",
            "type": "->",
            "args": [
                "SELECT COUNT(*) AS `numrows`\nFROM `tb_kelas`\nWHERE   (\nabjad) LIKE '%%' ESCAPE '!'\n )",
                0
            ]
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\Database\\BaseConnection.php",
            "line": 670,
            "function": "execute",
            "class": "CodeIgniter\\Database\\MySQLi\\Connection",
            "type": "->",
            "args": [
                "SELECT COUNT(*) AS `numrows`\nFROM `tb_kelas`\nWHERE   (\nabjad) LIKE '%%' ESCAPE '!'\n )"
            ]
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\Database\\BaseConnection.php",
            "line": 598,
            "function": "simpleQuery",
            "class": "CodeIgniter\\Database\\BaseConnection",
            "type": "->",
            "args": [
                "SELECT COUNT(*) AS `numrows`\nFROM `tb_kelas`\nWHERE   (\nabjad) LIKE '%%' ESCAPE '!'\n )"
            ]
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\Database\\BaseBuilder.php",
            "line": 1527,
            "function": "query",
            "class": "CodeIgniter\\Database\\BaseConnection",
            "type": "->",
            "args": [
                "SELECT COUNT(*) AS `numrows`\nFROM `tb_kelas`\nWHERE   (\nabjad) LIKE :abjad): ESCAPE '!'\n )",
                {
                    "abjad)": [
                        "%%",
                        true
                    ]
                },
                false
            ]
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\irsyadulibad\\codeigniter4-datatables\\src\\TableProcessor.php",
            "line": 35,
            "function": "countAllResults",
            "class": "CodeIgniter\\Database\\BaseBuilder",
            "type": "->",
            "args": [
                false
            ]
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\irsyadulibad\\codeigniter4-datatables\\src\\DataTableMethods.php",
            "line": 101,
            "function": "count",
            "class": "Irsyadulibad\\DataTables\\TableProcessor",
            "type": "->",
            "args": []
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\irsyadulibad\\codeigniter4-datatables\\src\\TableProcessor.php",
            "line": 42,
            "function": "filterRecords",
            "class": "Irsyadulibad\\DataTables\\DataTableMethods",
            "type": "->",
            "args": []
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\irsyadulibad\\codeigniter4-datatables\\src\\TableProcessor.php",
            "line": 27,
            "function": "doQuery",
            "class": "Irsyadulibad\\DataTables\\TableProcessor",
            "type": "->",
            "args": []
        },
        {
            "file": "D:\\Project\\Sekolah\\app\\Controllers\\KelasController.php",
            "line": 32,
            "function": "make",
            "class": "Irsyadulibad\\DataTables\\TableProcessor",
            "type": "->",
            "args": [
                true
            ]
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\CodeIgniter.php",
            "line": 824,
            "function": "ajaxList",
            "class": "App\\Controllers\\KelasController",
            "type": "->",
            "args": []
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\CodeIgniter.php",
            "line": 410,
            "function": "runController",
            "class": "CodeIgniter\\CodeIgniter",
            "type": "->",
            "args": [
                {
                    "kelas": {
                        "pager": null
                    },
                    "validation": {}
                }
            ]
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\CodeIgniter.php",
            "line": 318,
            "function": "handleRequest",
            "class": "CodeIgniter\\CodeIgniter",
            "type": "->",
            "args": [
                null,
                {
                    "handler": "file",
                    "backupHandler": "dummy",
                    "storePath": "D:\\Project\\Sekolah\\writable\\cache/",
                    "cacheQueryString": false,
                    "prefix": "",
                    "ttl": 60,
                    "reservedCharacters": "{}()/\\@:",
                    "file": {
                        "storePath": "D:\\Project\\Sekolah\\writable\\cache/",
                        "mode": 416
                    },
                    "memcached": {
                        "host": "127.0.0.1",
                        "port": 11211,
                        "weight": 1,
                        "raw": false
                    },
                    "redis": {
                        "host": "127.0.0.1",
                        "password": null,
                        "port": 6379,
                        "timeout": 0,
                        "database": 0
                    },
                    "validHandlers": {
                        "dummy": "CodeIgniter\\Cache\\Handlers\\DummyHandler",
                        "file": "CodeIgniter\\Cache\\Handlers\\FileHandler",
                        "memcached": "CodeIgniter\\Cache\\Handlers\\MemcachedHandler",
                        "predis": "CodeIgniter\\Cache\\Handlers\\PredisHandler",
                        "redis": "CodeIgniter\\Cache\\Handlers\\RedisHandler",
                        "wincache": "CodeIgniter\\Cache\\Handlers\\WincacheHandler"
                    }
                },
                false
            ]
        },
        {
            "file": "D:\\Project\\Sekolah\\public\\index.php",
            "line": 37,
            "function": "run",
            "class": "CodeIgniter\\CodeIgniter",
            "type": "->",
            "args": []
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\Commands\\Server\\rewrite.php",
            "line": 43,
            "args": [
                "D:\\Project\\Sekolah\\public\\index.php"
            ],
            "function": "require_once"
        }
    ]
}

Mohon untuk solusinya

dens4t commented 2 years ago

halo ada solusinya ga?

mdestafadilah commented 2 years ago

halo ada solusinya ga?

coba pake reguler query mysql biasa.

"message": "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 5",
meigiyanto commented 2 years ago

Kodingan saya untuk select concat yaitu

return DataTables::use('tb_kelas')
        ->select("id, CONCAT(tingkat, abjad) as kelas")
        ->addColumn('action', function($data) {
            return "<a href=\"" . base_url('Kelas/'. $data->id . "/ubah")."\" class=\"btn btn-sm btn-success mr-1\"><i class=\"fas fa-edit\"></i> Ubah</a>
            <a href=\"#\" onclick=\"konfirmasiHapus(" . $data->id .")\" class=\"btn btn-sm btn-danger\"><i class=\"fas fa-trash\"></i> Hapus</a>";
        })->rawColumns(['action'])
        ->make(true);

dan untuk isian columns datatable di halaman frontendnya yaitu id dan kelas

error yang didapatkan

{
    "title": "mysqli_sql_exception",
    "type": "mysqli_sql_exception",
    "code": 500,
    "message": "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 5",
    "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\Database\\MySQLi\\Connection.php",
    "line": 292,
    "trace": [
        {
            "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\Database\\MySQLi\\Connection.php",
            "line": 292,
            "function": "query",
            "class": "mysqli",
            "type": "->",
            "args": [
                "SELECT COUNT(*) AS `numrows`\nFROM `tb_kelas`\nWHERE   (\nabjad) LIKE '%%' ESCAPE '!'\n )",
                0
            ]
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\Database\\BaseConnection.php",
            "line": 670,
            "function": "execute",
            "class": "CodeIgniter\\Database\\MySQLi\\Connection",
            "type": "->",
            "args": [
                "SELECT COUNT(*) AS `numrows`\nFROM `tb_kelas`\nWHERE   (\nabjad) LIKE '%%' ESCAPE '!'\n )"
            ]
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\Database\\BaseConnection.php",
            "line": 598,
            "function": "simpleQuery",
            "class": "CodeIgniter\\Database\\BaseConnection",
            "type": "->",
            "args": [
                "SELECT COUNT(*) AS `numrows`\nFROM `tb_kelas`\nWHERE   (\nabjad) LIKE '%%' ESCAPE '!'\n )"
            ]
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\Database\\BaseBuilder.php",
            "line": 1527,
            "function": "query",
            "class": "CodeIgniter\\Database\\BaseConnection",
            "type": "->",
            "args": [
                "SELECT COUNT(*) AS `numrows`\nFROM `tb_kelas`\nWHERE   (\nabjad) LIKE :abjad): ESCAPE '!'\n )",
                {
                    "abjad)": [
                        "%%",
                        true
                    ]
                },
                false
            ]
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\irsyadulibad\\codeigniter4-datatables\\src\\TableProcessor.php",
            "line": 35,
            "function": "countAllResults",
            "class": "CodeIgniter\\Database\\BaseBuilder",
            "type": "->",
            "args": [
                false
            ]
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\irsyadulibad\\codeigniter4-datatables\\src\\DataTableMethods.php",
            "line": 101,
            "function": "count",
            "class": "Irsyadulibad\\DataTables\\TableProcessor",
            "type": "->",
            "args": []
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\irsyadulibad\\codeigniter4-datatables\\src\\TableProcessor.php",
            "line": 42,
            "function": "filterRecords",
            "class": "Irsyadulibad\\DataTables\\DataTableMethods",
            "type": "->",
            "args": []
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\irsyadulibad\\codeigniter4-datatables\\src\\TableProcessor.php",
            "line": 27,
            "function": "doQuery",
            "class": "Irsyadulibad\\DataTables\\TableProcessor",
            "type": "->",
            "args": []
        },
        {
            "file": "D:\\Project\\Sekolah\\app\\Controllers\\KelasController.php",
            "line": 32,
            "function": "make",
            "class": "Irsyadulibad\\DataTables\\TableProcessor",
            "type": "->",
            "args": [
                true
            ]
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\CodeIgniter.php",
            "line": 824,
            "function": "ajaxList",
            "class": "App\\Controllers\\KelasController",
            "type": "->",
            "args": []
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\CodeIgniter.php",
            "line": 410,
            "function": "runController",
            "class": "CodeIgniter\\CodeIgniter",
            "type": "->",
            "args": [
                {
                    "kelas": {
                        "pager": null
                    },
                    "validation": {}
                }
            ]
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\CodeIgniter.php",
            "line": 318,
            "function": "handleRequest",
            "class": "CodeIgniter\\CodeIgniter",
            "type": "->",
            "args": [
                null,
                {
                    "handler": "file",
                    "backupHandler": "dummy",
                    "storePath": "D:\\Project\\Sekolah\\writable\\cache/",
                    "cacheQueryString": false,
                    "prefix": "",
                    "ttl": 60,
                    "reservedCharacters": "{}()/\\@:",
                    "file": {
                        "storePath": "D:\\Project\\Sekolah\\writable\\cache/",
                        "mode": 416
                    },
                    "memcached": {
                        "host": "127.0.0.1",
                        "port": 11211,
                        "weight": 1,
                        "raw": false
                    },
                    "redis": {
                        "host": "127.0.0.1",
                        "password": null,
                        "port": 6379,
                        "timeout": 0,
                        "database": 0
                    },
                    "validHandlers": {
                        "dummy": "CodeIgniter\\Cache\\Handlers\\DummyHandler",
                        "file": "CodeIgniter\\Cache\\Handlers\\FileHandler",
                        "memcached": "CodeIgniter\\Cache\\Handlers\\MemcachedHandler",
                        "predis": "CodeIgniter\\Cache\\Handlers\\PredisHandler",
                        "redis": "CodeIgniter\\Cache\\Handlers\\RedisHandler",
                        "wincache": "CodeIgniter\\Cache\\Handlers\\WincacheHandler"
                    }
                },
                false
            ]
        },
        {
            "file": "D:\\Project\\Sekolah\\public\\index.php",
            "line": 37,
            "function": "run",
            "class": "CodeIgniter\\CodeIgniter",
            "type": "->",
            "args": []
        },
        {
            "file": "D:\\Project\\Sekolah\\vendor\\codeigniter4\\framework\\system\\Commands\\Server\\rewrite.php",
            "line": 43,
            "args": [
                "D:\\Project\\Sekolah\\public\\index.php"
            ],
            "function": "require_once"
        }
    ]
}

Mohon untuk solusinya

Halo gan, coba cek solusi di https://github.com/irsyadulibad/ci4-datatables/issues/30#issuecomment-1329337792 dan di commit ya?. Semoga membantu.