Insert and Update Record using drupal_write_record()

It saves a record to the database based upon the schema.

you can simply call the new drupal_write_record function telling it what database table to write to and the information to write and the function will do the rest. SO you'll find yourself writing less and less of those long db_query insert and update commands!

Insert Record To Table
This would insert all the data in the $node object into the node database table.

drupal_write_record('node', $node);

Example :
$objFile = new stdClass();
$objFile->uid = $uId;
$objFile->filemime = $arrFile['str_file_mime'];
$objFile->filesize = $arrFile['int_file_size'];
$objFile->status = FILE_STATUS_PERMANENT;
$objFile->timestamp = time();
drupal_write_record('files', $objFile);


Update Record In Table
This would update the node in the node database table with the data in the $node object 
where nid is equal to the $node->nid

drupal_write_record('node', $node, 'nid')


Example :
$strFileExtension = getFileExtension($arrFile['str_orgin_file_name']);
$strFileNewName = $objFile->fid.".".$strFileExtension;
$objFile->filename = $strFileNewName;
$objFile->filepath = $arrFile['str_rel_file_path'].$uId.DIRECTORY_SEPARATOR.$strFileNewName;
drupal_write_record('files', $objFile,'fid');