Whitespace fixes
Revised PHPdoc for file_add() function
Backport changes to file_add() function from master

Align with changes from 84017535f8718685d755d58af7a39d80f52ffca8
to ease future code maintenance.
Use bind variables in file_add() function

Use of db_query() in file_add() is causing issues on Oracle due to the
size of literal SQL statements being limited to 2000 chars: error
ORA-01704 occurs when attaching files with DB storage. To avoid the
problem, bind variables must be used.

We now call db_query_bound() instead of db_query(), and file_add() has
been refactored to remove usage of deprecated db_prepare_* functions.

Fixes #14563
Fix encoding of BLOB columns

The db_prepare_binary_string() function was designed for use with
db_query(), and therefore used to surround the binary string to
encode with single quotes.

Use of db_query_bound() with the function's return value would result in
a corrupted attachment because the quotes would be treated as integral
part of the binary data.

MySQL does not require any special encoding (except regular string
processing which is already done by db_query_bound()).

For PostgreSQL, instead of calling pg_escape_bytea() directly, we now
use ADOdb connection's BlobEncode() method.

MSSQL encoding was left as is was (no test platform available).

Based on documentation, Oracle (oci8) should not require any encoding
either, but was not tested either.

Fixes #12955
Move error checking code to beginning of file_add() function
SOAP API: align mci_file_add() with core file_add()

Most importantly, use bind variables (db_query_bound) and remove
deprecated db_prepare_* function calls.

A few other, minor changes were made to ensure mci_file_add() is as
similar as possible as the core file_add(), and the two functions behave
in a consistent way.
Whitespace fixes
SOAP tests: fix issue with testProjectAttachmentIsAdded()

The assertions for the project attachments are incorrect, as the rely on
there being no existing files, consequently the test fails if there are
any existing documents attached.

Added messages on assertions to facilitate troubleshooting.
Fix errors in mc_file_add()

SYSTEM NOTICE errors were detected by phpunit tests.
Remove calls to deprecated functions db_prepare* in "Docs" update page

Those calls cause the strings to be escaped twice : by db_prepare* and
then by db_query_bound, which leads to backslashes apparing in the
database.

All c_ prefixed variables have been removed as well, as there is no need
anymore for SQL cleaned variables.

Fixes #14541

Signed-off-by: Damien Regad <damien.regad@merckgroup.com>
Merge of branch 'file-attach-fixes'

Conflicts:
	core/file_api.php
	tests/soap/AttachmentTest.php
UserTest: preferences should compare against default value

Previously the test was comparing the retrieved user preference
'bugnote_order' with a hardcoded value, so the test would fail if the
config_inc settings were different.

Fixes #16204
IssueHistoryTest: Fix Whitespace
IssueHistoryTest: use MantisBT constants
IssueHistoryTest: fix failure when using descending order

Tests would incorrectly be marked as failure when $g_history_order is
set to DESC, as the cases assume the default of ASC.

Fixes #16205
IssueHistoryTest: fix random failure with simultaneous entries

This happens when history entries are created in rapid sequence (i.e.
within the same second), and the RDBMS then returns the records in
random order. Since the tests rely on a fixed order of the entries, this
occasionally causes failures.

Fixes #16203