DB Exception and I cant figure it

DB Exception and I cant figure it

by Daniel Mc Sweeney -
Number of replies: 5

Hi,

I'm developing the course request manager block. Im developing in a mac and mysql environment and all seems well. However one of my users is reporting an error on SQL server. Its the only error report that I have had like this.


The debug info is as follows


Debug info:
Error code: codingerror
Stack trace:

line 1056 of \lib\dml\sqlsrv_native_moodle_database.php: coding_exception thrown
line 1108 of \lib\dml\sqlsrv_native_moodle_database.php: call to sqlsrv_native_moodle_database->update_record_raw()
line 270 of \blocks\cmanager\course_request.php: call to sqlsrv_native_moodle_database->update_record()


I've checked the line on 270 of my code and Im just doing a record update.

$DB->update_record('block_cmanager_records', $newrec);


When I echo the $newrec object it looks ok

O:8:"stdClass":4:{s:2:"id";i:4;s:7:"modname";s:3:"qwe";s:7:"modcode";s:3:"qwe";s:7:"modmode";s:9:"Full Time";}


The following is the declaration for the table

<TABLE NAME="block_cmanager_records" COMMENT="block_cmanager_records table retrofitted from MySQL" PREVIOUS="block_cmanager_form_data">
      <FIELDS>
        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true"  NEXT="createdbyid"/>
        <FIELD NAME="createdbyid" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false"  PREVIOUS="id" NEXT="modname"/>
        <FIELD NAME="modname" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"  PREVIOUS="createdbyid" NEXT="modcode"/>
        <FIELD NAME="modcode" TYPE="char" LENGTH="100" NOTNULL="false" SEQUENCE="false"  PREVIOUS="modname" NEXT="modmode"/>
        <FIELD NAME="modmode" TYPE="char" LENGTH="50" NOTNULL="false" SEQUENCE="false"  PREVIOUS="modcode" NEXT="modkey"/>
        <FIELD NAME="modkey" TYPE="char" LENGTH="50" NOTNULL="false" SEQUENCE="false"  PREVIOUS="modmode" NEXT="cate"/>
        <FIELD NAME="cate" TYPE="char" LENGTH="200" NOTNULL="false" SEQUENCE="false"  PREVIOUS="modkey" NEXT="status"/>
        <FIELD NAME="status" TYPE="char" LENGTH="50" NOTNULL="false" SEQUENCE="false"  PREVIOUS="cate" NEXT="req_type"/>
        <FIELD NAME="req_type" TYPE="char" LENGTH="200" NOTNULL="false" SEQUENCE="false"  PREVIOUS="status" NEXT="req_values"/>
        <FIELD NAME="req_values" TYPE="char" LENGTH="20" NOTNULL="false" SEQUENCE="false"  PREVIOUS="req_type" NEXT="createdate"/>
        <FIELD NAME="createdate" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false"  PREVIOUS="req_values" NEXT="formid"/>
        <FIELD NAME="formid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false"  PREVIOUS="createdate" NEXT="c1"/>
        <FIELD NAME="c1" TYPE="char" LENGTH="300" NOTNULL="true" SEQUENCE="false"  PREVIOUS="formid" NEXT="c2"/>
        <FIELD NAME="c2" TYPE="char" LENGTH="300" NOTNULL="true" SEQUENCE="false"  PREVIOUS="c1" NEXT="c3"/>
        <FIELD NAME="c3" TYPE="char" LENGTH="300" NOTNULL="true" SEQUENCE="false"  PREVIOUS="c2" NEXT="c4"/>
        <FIELD NAME="c4" TYPE="char" LENGTH="300" NOTNULL="true" SEQUENCE="false"  PREVIOUS="c3" NEXT="c5"/>
        <FIELD NAME="c5" TYPE="char" LENGTH="300" NOTNULL="true" SEQUENCE="false"  PREVIOUS="c4" NEXT="c6"/>
        <FIELD NAME="c6" TYPE="char" LENGTH="300" NOTNULL="true" SEQUENCE="false"  PREVIOUS="c5" NEXT="c7"/>
        <FIELD NAME="c7" TYPE="char" LENGTH="300" NOTNULL="true" SEQUENCE="false"  PREVIOUS="c6" NEXT="c8"/>
        <FIELD NAME="c8" TYPE="char" LENGTH="300" NOTNULL="true" SEQUENCE="false"  PREVIOUS="c7" NEXT="c9"/>
        <FIELD NAME="c9" TYPE="char" LENGTH="300" NOTNULL="true" SEQUENCE="false"  PREVIOUS="c8" NEXT="c10"/>
        <FIELD NAME="c10" TYPE="char" LENGTH="300" NOTNULL="true" SEQUENCE="false"  PREVIOUS="c9" NEXT="c11"/>
        <FIELD NAME="c11" TYPE="char" LENGTH="300" NOTNULL="true" SEQUENCE="false"  PREVIOUS="c10" NEXT="c12"/>
        <FIELD NAME="c12" TYPE="char" LENGTH="300" NOTNULL="true" SEQUENCE="false"  PREVIOUS="c11" NEXT="c13"/>
        <FIELD NAME="c13" TYPE="char" LENGTH="300" NOTNULL="true" SEQUENCE="false"  PREVIOUS="c12" NEXT="c14"/>
        <FIELD NAME="c14" TYPE="char" LENGTH="300" NOTNULL="true" SEQUENCE="false"  PREVIOUS="c13" NEXT="c15"/>
        <FIELD NAME="c15" TYPE="char" LENGTH="300" NOTNULL="true" SEQUENCE="false"  PREVIOUS="c14"/>
      </FIELDS>
      <KEYS>
        <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
      </KEYS>
    </TABLE>


I'm stumped!! Tables on the users installation are MSSQL 2008r2 LATIN1_GENERAL_CI_AI


Anyone shed any light on this for me? Thanks!

Dan


Average of ratings: -
In reply to Daniel Mc Sweeney

Re: DB Exception and I cant figure it

by Pinky Sharma -

Hi Denial,

Why is your $newrec object is encoded ? I think it should be a simple object with contents equal to fieldname => fieldvalue and must have id to map to the specified record. For ex -

$newrec = new stdClass();

$newrec->id = $record->id;

$newrec->modname = 'modulename';

$newrec->modcode = '5';

$DB->update_record('tablename', $newrec);

Hope this will help you.




Average of ratings: Useful (1)
In reply to Pinky Sharma

Re: DB Exception and I cant figure it

by Daniel Mc Sweeney -

Hi,

just looking at this today, I cant see where I have that object encoded

"$newrec object is encoded"

Did you spot something in the code that I missed?

Thanks

In reply to Daniel Mc Sweeney

Re: DB Exception and I cant figure it

by Conn Warwicker -
Picture of Core developers Picture of Plugin developers

Hi,

You said when you echo your object it prints out this:

O:8:"stdClass":4:{s:2:"id";i:4;s:7:"modname";s:3:"qwe";s:7:"modcode";s:3:"qwe";s:7:"modmode";s:9:"Full Time";}


That means that variable is a serialized object.

If you want to return it to being a standard object you can use, run it through unserialize()

Average of ratings: Useful (1)