Welcome Guest, Not a member yet? Register   Sign In
stdClass/row array results to uppercase
#1

[eluser]anndr0id[/eluser]
So I've got my SQL queries working beautifully and returning all the data from my oracle database.

Problem is that its returning the array in caps, and all my calls are in mySQL format still. ($row->tableID, whereas oracle is returning $row->TABLEID)

I'm figuring rather than go through and change thousands of references in the code to uppercase, that a well placed strtoupper or array_change_key_case somewhere in the codeigniter code could solve my problem.

So I'm a newbie at codeigniter, but I'm hoping someone could point me in the right way of the function/reference/place I should be looking to find the function thats activated when a specific row of an array is referenced after the database query?

in example:
Code:
$query = $this->db->get('table');
foreach ($query->result() as $row) {
    $row->tableID; //This is the functionality I'm looking for
}

So basically I need to find where the value "tableID" is being referenced in a function so I can throw a little strtoupper around it.

*crosses fingers*
#2

[eluser]xwero[/eluser]
Can't you let your editor do it for you? Something like : replace all files /\$row\->([a-zA-Z_]+)/ strtoupper($1).

I think there is no way of changing the case of a hardcoded string dynamically.
#3

[eluser]anndr0id[/eluser]
I tried that, but considering its treated as a variable, the string to upper function doesn't work in that way, so I've got no other choice but to go in, highlight them all, and uppercase them. Its rather depressing. heh.

[quote author="xwero" date="1205960910"]Can't you let your editor do it for you? Something like : replace all files /\$row\->([a-zA-Z_]+)/ strtoupper($1).

I think there is no way of changing the case of a hardcoded string dynamically.[/quote]
#4

[eluser]xwero[/eluser]
Welcome to the world of webdevelopment Wink
#5

[eluser]anndr0id[/eluser]
[quote author="xwero" date="1205972261"]Welcome to the world of webdevelopment Wink[/quote]

Yeah, I realized that when my doctor wasn't sure whether to describe me anti depressants or ADD medication. haha.

I actually somehow convinced IT to let me into the database to change it by some miracle of god or the fact that I was about to cry. lol. So all is once again good in the world, or at least my application.
#6

[eluser]inari[/eluser]
I hate that Oracle capitalization. Can't anyone help... please... I am new to CI too.

It is impossible to easily switch between mysql and Oracle with this big issue.
And my variables looks ugly now Smile

Come on, someone smart is needed now.
#7

[eluser]inari[/eluser]
Well, I was little in hurry so I fixed it by myself. This fix works only for PHP 5.


To get object attributes lowercase do next:

1. go to db_result.php near line 75
2. find method result_object()
3. change:
Code:
while ($row = $this->_fetch_object())
        {
            $this->result_object[] = $row;
        
        }
with:
Code:
while ($row = $this->_fetch_object())
        {
            $new_row = array();
            foreach ($row as $key => $value) {
                    $new_row[strtolower($key)] = $value;
            }
            $this->result_object[] = (object) $new_row;
        
        }

And for getting result as array:

1. open oci8_result.php
2. find method result_array()
3. change:

Code:
while ($this->_fetch_assoc($row))
        {
            
            $this->result_array[] = $row;
        }

with:

Code:
while ($this->_fetch_assoc($row))
        {
            
            $new_row = array();
            foreach ($row as $key => $value) {
                    $new_row[strtolower($key)] = $value;
            }
            
            $this->result_array[] = $new_row;
        }




Theme © iAndrew 2016 - Forum software by © MyBB