Файл: Проце‬ссы при‬нятия решений в организации.pdf

ВУЗ: Не указан

Категория: Курсовая работа

Дисциплина: Не указана

Добавлен: 14.03.2024

Просмотров: 46

Скачиваний: 0

ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.

If the escape value was not set will will base it on the global setting if ( ! is_bool(escape)) escape this_protect_identifiers;

foreach (key as k v) prefix (count(thisar_where) 0 AND count(thisar_cache_where) 0) ? "": type;

if (is_null(v) ! this_has_operator(k)) value appears not to have been set, assign the test to IS NULL k. " IS NULL";

if ( ! is_null(v)) if (escape TRUE) k this_protect_identifiers(k, FALSE, escape);

v " ".thisescape(v);

if ( ! this_has_operator(k)) k. " ";

else k this_protect_identifiers(k, FALSE, escape);

thisar_where prefix.k.v; if (thisar_caching TRUE) thisar_cache_where prefix.k.v; thisar_cache_exists "where";

return this; Where_in Generates a WHERE field IN ("item", "item") SQL query joined with AND if appropriate access public param string The field to search param array The values searched on return object function where_in(key NULL, values NULL) return this_where_in(key, values);

Where_in_or Generates a WHERE field IN ("item", "item") SQL query joined with OR if appropriate access public param string The field to search param array The values searched on return object function or_where_in(key NULL, values NULL) return this_where_in(key, values, FALSE, "OR ");

Where_not_in Generates a WHERE field NOT IN ("item", "item") SQL query joined with AND if appropriate access public param string The field to search param array The values searched on return object function where_not_in(key NULL, values NULL) return this_where_in(key, values, TRUE);

Where_not_in_or Generates a WHERE field NOT IN ("item", "item") SQL query joined with OR if appropriate access public param string The field to search param array The values searched on return object function or_where_not_in(key NULL, values NULL) return this_where_in(key, values, TRUE, "OR ");

Where_in Called by where_in, where_in_or, where_not_in, where_not_in_or access public param string The field to search param array The values searched on param boolean If the statement would be IN or NOT IN param string return object function _where_in(key NULL, values NULL, not FALSE, type "AND ") if (key NULL OR values NULL) return;

if ( ! is_array(values)) values array(values);

not (not) ? " NOT": "";

foreach (values as value) thisar_wherein thisescape(value);

prefix (count(thisar_where) 0) ? "": type;

where_in prefix. this_protect_identifiers(key). not.. implode(, thisar_wherein).;

thisar_where where_in;

if (thisar_caching TRUE) thisar_cache_where where_in;

thisar_cache_exists "where";

reset the array for multiple calls thisar_wherein array();

return this;

Like Generates a LIKE portion of the query. Separates multiple calls with AND access public param mixed param mixed return object function like(field, match "", side "both") return this_like(field, match, "AND ", side);

Not Like Generates a NOT LIKE portion of the query. Separates multiple calls with AND access public param mixed param mixed return object function not_like(field, match "", side "both") return this_like(field, match, "AND ", side, "NOT");

OR Like Generates a LIKE portion of the query. Separates multiple calls with OR access public param mixed param mixed return object function or_like(field, match "", side "both") return this_like(field, match, "OR ", side);

OR Not Like Generates a NOT LIKE portion of the query. Separates multiple calls with OR access public param mixed param mixed return object function or_not_like(field, match "", side "both") return this_like(field, match, "OR ", side, "NOT");

orlike() is an alias of or_like() this function is here for backwards compatibility, as orlike() has been deprecated function orlike(field, match "", side "both") return thisor_like(field, match, side);

Like Called by like() or orlike() access private param mixed param mixed param string return object function _like(field, match "", type "AND ", side "both", not "") if ( ! is_array(field)) field array(field match);

foreach (field as k v) k this_protect_identifiers(k);

prefix (count(thisar_like) 0) ? "": type;

v thisescape_str(v);

if (side "before") like_statement prefix." k not LIKE """;

elseif (side "after") like_statement prefix." k not LIKE """;

else like_statement prefix." k not LIKE """;

thisar_like like_statement;

if (thisar_caching TRUE) thisar_cache_like like_statement;


thisar_cache_exists "like";

return this;

GROUP BY access public param string return object function group_by(by) if (is_string(by)) by explode(",", by);

foreach (by as val) val trim(val);

if (val ! "")

thisar_groupby this_protect_identifiers(val);

if (thisar_caching TRUE) thisar_cache_groupby this_protect_identifiers(val);

thisar_cache_exists "groupby";

return this;

groupby() is an alias of group_by() this function is here for backwards compatibility, as groupby() has been deprecated function groupby(by) return thisgroup_by(by);

} Sets the HAVING value Separates multiple calls with AND access public param string param string return object function having(key, value "", escape TRUE) return this_having(key, value, "AND ", escape);

orhaving() is an alias of or_having() this function is here for backwards compatibility, as orhaving() has been deprecated function orhaving(key, value "", escape TRUE) return thisor_having(key, value, escape);

} Sets the OR HAVING value Separates multiple calls with OR access public param string param string return object function or_having(key, value "", escape TRUE) return this_having(key, value, "OR ", escape);

Sets the HAVING values Called by having() or or_having() access private param string param string return object function _having(key, value "", type "AND ", escape TRUE) if ( ! is_array(key)) key array(key value);

foreach (key as k v) prefix (count(thisar_having) 0) ? "": type;

if (escape TRUE) k this_protect_identifiers(k);

if ( ! this_has_operator(k)) k. " ";

if (v ! "")

v " ".thisescape_str(v);

thisar_having prefix.k.v;

if (thisar_caching TRUE) thisar_cache_having prefix.k.v;

thisar_cache_exists "having";

return this;

Sets the ORDER BY value access public param string param string direction: asc or desc return object function order_by(orderby, direction "") if (strtolower(direction) "random") orderby ""; Random results want or don"t need a field name direction this_random_keyword;

elseif (trim(direction) ! "")

direction (in_array(strtoupper(trim(direction)), array("ASC", "DESC"), TRUE)) ? " ".direction: " ASC";

if (strpos(orderby, ",") ! FALSE) temp array();

foreach (explode(",", orderby) as part) part trim(part);

if ( ! in_array(part, thisar_aliased_tables)) part this_protect_identifiers(trim(part));

temp part;

orderby implode(", ", temp);

else if (direction ! this_random_keyword) orderby this_protect_identifiers(orderby);

orderby_statement orderby.direction;

thisar_orderby orderby_statement;

if (thisar_caching TRUE) thisar_cache_orderby orderby_statement;

thisar_cache_exists "orderby";

return this;

orderby() is an alias of order_by() this function is here for backwards compatibility, as orderby() has been deprecated function orderby(orderby, direction "") return thisorder_by(orderby, direction);

Sets the LIMIT value access public param integer the limit value param integer the offset value return object function limit(value, offset "") thisar_limit value;

if (offset ! "")

thisar_offset offset;

return this;

Sets the OFFSET value access public param integer the offset value return object function offset(offset) thisar_offset offset;

return this;

The function. Allows keyvalue pairs to be set for inserting or updating access public param mixed param string param boolean return object function set(key, value "", escape TRUE) key this_object_to_array(key);

if ( ! is_array(key)) key array(key value);

} foreach (key as k v) if (escape FALSE) thisar_set[this_protect_identifiers(k)] v;

else thisar_set[this_protect_identifiers(k)] thisescape(v);

return this;

Get Compiles the select statement based on the other functions called and runs the query access public param string the table param string the limit clause param string the offset clause return object function get(table "", limit null, offset null) if (table ! "")

this_track_aliases(table);

thisfrom(table);

if ( ! is_null(limit)) thislimit(limit, offset);

sql this_compile_select();

result thisquery(sql);

this_reset_select();

return result;

"Count All Results" query Generates a platformspecific query string that counts all records returned by an Active Record query.


access public param string return string function count_all_results(table "") if (table ! "")

this_track_aliases(table);

thisfrom(table);

sql this_compile_select(this_count_string. this_protect_identifiers("numrows"));

query thisquery(sql);

this_reset_select();

if (querynum_rows() 0) return "0";

row queryrow();

return rownumrows;

Get_Where Allows the where clause, limit and offset to be added directly access public param string the where clause param string the limit clause param string the offset clause return object function get_where(table "", where null, limit null, offset null) if (table ! "")

thisfrom(table);

if ( ! is_null(where)) thiswhere(where);

if ( ! is_null(limit)) thislimit(limit, offset); sql this_compile_select(); result thisquery(sql); this_reset_select();

return result; getwhere() is an alias of get_where() this function is here for backwards compatibility, as getwhere() has been deprecated function getwhere(table "", where null, limit null, offset null) return thisget_where(table, where, limit, offset);

Insert Compiles an insert string and runs the query access public param string the table to retrieve the results from param array an associative array of insert values return object function insert(table "", set NULL) { if ( ! is_null(set)) thisset(set);

if (count(thisar_set) 0) if (thisdb_debug) return thisdisplay_error("db_must_use_set");

return FALSE; if (table "") if ( ! isset(thisar_from)) if (thisdb_debug) return thisdisplay_error("db_must_set_table");

return FALSE; table thisar_from;

sql this_insert(this_protect_identifiers(table, TRUE, NULL, FALSE), array_keys(thisar_set), array_values(thisar_set));

this_reset_write();

return thisquery(sql);

Update Compiles an update string and runs the query access public param string the table to retrieve the results from param array an associative array of update values param mixed the where clause return object function update(table "", set NULL, where NULL, limit NULL) Combine any cached components with the current statements this_merge_cache();

if ( ! is_null(set)) thisset(set);

if (count(thisar_set) 0) if (thisdb_debug) return thisdisplay_error("db_must_use_set");

return FALSE;

if (table "") if ( ! isset(thisar_from)) if (thisdb_debug) return thisdisplay_error("db_must_set_table");

return FALSE;

table thisar_from;

if (where ! NULL) thiswhere(where);

if (limit ! NULL) thislimit(limit);

sql this_update(this_protect_identifiers(table, TRUE, NULL, FALSE), thisar_set, thisar_where, thisar_orderby, thisar_limit);

this_reset_write();

return thisquery(sql);

Empty Table Compiles a delete string and runs "DELETE FROM table" access public param string the table to empty return object function empty_table(table "") if (table "") if ( ! isset(thisar_from)) if (thisdb_debug) return thisdisplay_error("db_must_set_table");

return FALSE;

table thisar_from;

else table this_protect_identifiers(table, TRUE, NULL, FALSE);

sql this_delete(table);

this_reset_write();

return thisquery(sql);

Truncate Compiles a truncate string and runs the query If the database does not support the truncate() command This function maps to "DELETE FROM table" access public param string the table to truncate return object function truncate(table "") if (table "") if ( ! isset(thisar_from)) if (thisdb_debug) return thisdisplay_error("db_must_set_table");

return FALSE;

table thisar_from;

else table this_protect_identifiers(table, TRUE, NULL, FALSE);

sql this_truncate(table);

this_reset_write();

return thisquery(sql);

Delete Compiles a delete string and runs the query access public param mixed the table(s) to delete from. String or array param mixed the where clause param mixed the limit clause param boolean return object function delete(table "", where "", limit NULL, reset_data TRUE) Combine any cached components with the current statements this_merge_cache();

if (table "") if ( ! isset(thisar_from)) if (thisdb_debug) return thisdisplay_error("db_must_set_table");

return FALSE;

table thisar_from;

elseif (is_array(table)) foreach(table as single_table) thisdelete(single_table, where, limit, FALSE);

this_reset_write();

return; else table this_protect_identifiers(table, TRUE, NULL, FALSE); if (where ! "") thiswhere(where);


if (limit ! NULL) thislimit(limit); if (count(thisar_where) 0 count(thisar_wherein) 0 count(thisar_like)) if (thisdb_debug) return thisdisplay_error("db_del_must_use_where");

return FALSE;

} sql this_delete(table, thisar_where, thisar_like, thisar_limit);

if (reset_data) this_reset_write();

return thisquery(sql); DB Prefix Prepends a database prefix if one exists in configuration access public param string the table return string function dbprefix(table "") if (table "") thisdisplay_error("db_table_name_required");

return thisdbprefix.table;

Track Aliases Used to track SQL statements written with aliased tables.

access private param string The table to inspect return string function _track_aliases(table) if (is_array(table)) foreach (table as t) this_track_aliases(t); return; Does the string contain a comma? If so, we need to separate the string into discreet statements if (strpos(table, ",") ! FALSE) return this_track_aliases(explode(",", table));

if a table alias is used we can recognize it by a space if (strpos(table, ) ! FALSE) if the alias is written with the AS keyword, remove it table preg_replace(" AS i", " ", table);

Grab the alias table trim(strrchr(table, ));

Store the alias, if it doesn"t already exist if ( ! in_array(table, thisar_aliased_tables)) thisar_aliased_tables table;

Compile the SELECT statement Generates a query string based on which functions were used.

Should not be called directly. The get() function calls it.

access private return string function _compile_select(select_override FALSE) Combine any cached components with the current statements this_merge_cache();

Write the portion of the query if (select_override ! FALSE) sql select_override;

else sql ( ! thisar_distinct) ? "SELECT ": "SELECT DISTINCT ";

if (count(thisar_select) 0) sql. "";

else { Cycle through the portion of the query and prep each column name.

The reason we protect identifiers here rather then in the select() function is because until the user calls the from() function we don"t know if there are aliases foreach (thisar_select as key val) thisar_select this_protect_identifiers(val);

sql. implode(", ", thisar_select);

Write the portion of the query if (count(thisar_from) 0) sql.;

sql. this_from_tables(thisar_from);

Write the portion of the query if (count(thisar_join) 0) sql.;

sql. implode(, thisar_join);

Write the portion of the query if (count(thisar_where) 0 OR count(thisar_like) 0) sql.; sql.; sql. implode(, thisar_where);

Write the portion of the query if (count(thisar_like) 0) if (count(thisar_where) 0) sql.; sql. implode(, thisar_like);

Write the portion of the query if (count(thisar_groupby) 0) sql.; sql. implode(", ", thisar_groupby);

Write the portion of the query if (count(thisar_having) 0) sql.; sql. implode(, thisar_having);

Write the portion of the query if (count(thisar_orderby) 0) sql.; sql. implode(", ", thisar_orderby);

if (thisar_order ! FALSE) sql. (thisar_order "desc") ? " DESC": " ASC"; } Write the portion of the query if (is_numeric(thisar_limit)) sql.; sql this_limit(sql, thisar_limit, thisar_offset);

return sql; Object to Array Takes an object as input and converts the class variables to array keyvals access public param object return array function _object_to_array(object) if ( ! is_object(object)) return object; array array(); foreach (get_object_vars(object) as key val) There are some built in keys we need to ignore for this conversion if ( ! is_object(val) ! is_array(val) key ! "_parent_name" key ! "_ci_scaffolding" key ! "_ci_scaff_table") array val;

return array; Start Cache Starts AR caching access public return void function start_cache() thisar_caching TRUE;

Stop Cache Stops AR caching access public return void function stop_cache() thisar_caching FALSE;

Flush Cache Empties the AR cache access public return void function flush_cache() { this_reset_run( array( "ar_cache_select" array(), "ar_cache_from" array(), "ar_cache_join" array(), "ar_cache_where" array(), "ar_cache_like" array(), "ar_cache_groupby" array(), "ar_cache_having" array(), "ar_cache_orderby" array(), "ar_cache_set" array(), "ar_cache_exists" array() );

Merge Cache When called, this function merges any cached AR arrays with locally called ones.

access private return void function _merge_cache() if (count(thisar_cache_exists) 0) return;


foreach (thisar_cache_exists as val) ar_variable "ar_".val;

ar_cache_var "ar_cache_".val;

if (count(thisar_cache_var) 0) continue;

thisar_variable array_unique(array_merge(thisar_cache_var, thisar_variable));

If we are "protecting identifiers" we need to examine the portion of the query to determine if there are any aliases if (this_protect_identifiers TRUE AND count(thisar_cache_from) 0) this_track_aliases(thisar_from);

Resets the active record values. Called by the get() function access private param array An array of fields to reset return void function _reset_run(ar_reset_items) foreach (ar_reset_items as item default_value) if ( ! in_array(item, thisar_store_array)) thisitem default_value;

Resets the active record values. Called by the get() function access private return void function _reset_select() ar_reset_items array( "ar_select" array(), "ar_from" array(), "ar_join" array(), "ar_where" array(), "ar_like" array(), "ar_groupby" array(), "ar_having" array(), "ar_orderby" array(), "ar_wherein" array(), "ar_aliased_tables" array(), "ar_distinct" FALSE, "ar_limit" FALSE, "ar_offset" FALSE, "ar_order" FALSE, );

this_reset_run(ar_reset_items); Resets the active record values.

Called by the insert() update() and delete() functions access private return void function _reset_write() { ar_reset_items array( "ar_set" array(), "ar_from" array(), "ar_where" array(), "ar_like" array(), "ar_orderby" array(), "ar_limit" FALSE, "ar_order" FALSE );

this_reset_run(ar_reset_items);

class CI_DB_odbc_driver extends CI_DB { var dbdriver "odbc";

the character used to excape not necessary for ODBC var _escape_char "";

The syntax to count rows is slightly different across different database engines, so this string appears in each driver and is used for the count_all() and count_all_results() functions.

var _count_string "SELECT COUNT() AS ";

var _random_keyword;

function CI_DB_odbc_driver(params) parent:CI_DB(params);

this_random_keyword " RND(".time().")"; database specific random keyword Nonpersistent database connection access private called by the base class return resource function db_connect() return odbc_connect(thishostname, thisusername, thispassword);

Persistent database connection access private called by the base class return resource function db_pconnect() return odbc_pconnect(thishostname, thisusername, thispassword);

Select the database access private called by the base class return resource function db_select() Not needed for ODBC return TRUE;

Set client character set access public param string param string return resource function db_set_charset(charset, collation) todo add support if needed return TRUE;

Version number query string access public return string function _version() return "SELECT version() AS ver";

Execute the query access private called by the base class param string an SQL query return resource function _execute(sql) sql this_prep_query(sql);

return odbc_exec(thisconn_id, sql);

Prep the query If needed, each database adapter can prep the query string access private called by execute() param string an SQL query return string function _prep_query(sql) return sql;

Begin Transaction access public return bool function trans_begin(test_mode FALSE) if ( ! thistrans_enabled) return TRUE;

When transactions are nested we only begincommitrollback the outermost ones if (this_trans_depth 0) return TRUE;

Reset the transaction failure flag.

If the test_mode flag is set to TRUE transactions will be rolled back even if the queries produce a successful result.

this_trans_failure (test_mode TRUE) ? TRUE: FALSE;

return odbc_autocommit(thisconn_id, FALSE);

Commit Transaction access public return bool function trans_commit() if ( ! thistrans_enabled) return TRUE;

When transactions are nested we only begincommitrollback the outermost ones if (this_trans_depth 0) return TRUE;

ret odbc_commit(thisconn_id);

odbc_autocommit(thisconn_id, TRUE);

return ret;

Rollback Transaction access public return bool function trans_rollback() if ( ! thistrans_enabled) return TRUE;

When transactions are nested we only begincommitrollback the outermost ones if (this_trans_depth 0) return TRUE;

ret odbc_rollback(thisconn_id);

odbc_autocommit(thisconn_id, TRUE);

return ret;