안녕하세요
New SQL Query 기능을 통해 데이터베이스를 업데이트하고 싶습니다.
Names Default To Here( 1 );
obj = New SQL Query(
Connection("DB connection string"),
Custom SQL "
UPDATE table
SET Column_1 = 1
where Column_2 = '2'
")
);
Error_Msg = Log capture( obj << Run;);다음과 같은 오류 메시지가 나타납니다.
""
Error running SQL Query:
[Server] Invalid object name table
로그 캡처는 빈 "" 문자열만 가져옵니다. 따라서 오류가 발생하지 않으면 빈 문자열을 반환하므로 쿼리가 성공했는지 알 수 없습니다.
비슷한 주제이지만 데이터베이스가 열려 있습니다. https://community.jmp.com/t5/Discussions/Catching-database-error-message/mp/6749#M6743
고마워
짧은 버전:
E_Msg = Log capture(
EXECUTE SQL(
create database connection("DB_String");
,
"SQL string"
);
);EXECUTE SQL 함수를 사용하면 더 나은 행운을 누릴 수 있습니다.저는 EXECUTE SQL 위에 LOG_EXECUTE_SQL이라는 함수를 작성했습니다. 이 함수는 오류를 찾아서 오류가 발견되면 오류와 오류를 일으킨 SQL이 포함된 텍스트 상자를 표시합니다.또한 전역 변수를 설정하여 모든 호출에 대한 SQL을 표시할 수 있습니다.
//------------------------------------------------------------------------------
/*
Function Name: log_execute_sql
Description: Execute SQL and trap ODBC errors found in the log file. If any are
found, display a warning message to the user. If the global variable
::g_log_execute_sql_debug flag is set to 1, display the SQL before
executing it
Arguments:
_caller Calling program. This will be included in the error message
_dbc database connection created with create database connection call
_sql sql statement to run
_invisible If 1, set the invisible flag. If 0, don't set it.
_tbl_name Optional table name to give the returned results table
Subprograms: execute sql
clear log
get log
Returns: pointer to dataset
Comments:
This preference is optional but good to use:
pref(ODBC Hide Connection String(1)); // Don't show connection string in dataset
Example calls:
1. Retrieve data from a table into an invisible dataset
pname = "Main Program";
dbc = Create Database Connection(::db_dsn); // ::db_dsn contains your database connection string
// The two colons means this is a global variable btw
// Get values from PARAMETERS table
sql_statement =
"SELECT rp.parameter_name, rp.parameter_value
FROM myschema.my_parameters rp";
param_dataset = log_execute_sql(pname, dbc, sql_statement, 1, "My Parameters");
close database connection(dbc);
2. Execute an INSERT statement:
dbc = Create Database Connection(::db_dsn); // ::db_dsn contains your database connection string
sql_statement = evalinsert(
"INSERT INTO myschema.my_activity_log
(user_created, date_created, my_section, activity, parameter1, value1, parameter2, value2,
parameter3, value3, parameter4, value4, parameter5, value5, parameter6, value6, parameter7, value7,
parameter8, value8)
VALUES ('^one_current_user_id^', CURRENT_DATE, 'DASHBOARD', 'REFRESH', 'Product Name', '^product_name_txt^',
'Owner', '^owner_txt^', 'Search Event Text', '^search_event_txt^', 'Date From', '^date_from_txt^',
'Date To', '^date_to_txt^', 'Alert Status', '^alert_status_txt^', 'Event Types', '^concat_event_types_list^',
'Alert Types', '^concat_alert_types_list^')");
// Run this SQL. No table is retrieved as it's a simple insert
log_execute_sql(pname, dbc, sql_statement, 0, "");
// Close the database connection - end of initialization queries
Close Database Connection(dbc);
*/
log_execute_SQL = function({_caller, _dbc, _sql, _invisible, _tbl_name},
{Default Local},
if (isempty(_dbc),
_nw = new window("log_execute_sql: Empty Value", << modal,
textbox("Error in log_execute_sql: The database connection is empty."),
);
throw("Empty database connection string");
);
if (isempty(_sql) | _sql == "",
_nw = new window("log_execute_sql: Empty Value", << modal,
textbox("Error in log_execute_sql: The SQL statement is empty."),
);
throw("Empty SQL string");
);
// Check the debug flag
_debug = 0;
if (! is empty(global:g_log_execute_sql_debug),
_debug = global:g_log_execute_sql_debug;
);
if (_debug,
_nw = new window("log_execute_sql DEBUG", << modal,
lineup box(ncol(2),
text box("_caller: "), text box(_caller),
text box("_dbc: "), text box(char(_dbc)),
text box("_invisible: "), text box(char(_invisible)),
text box("_tbl_name: "), text box(_tbl_name),
),
panel box("SQL",
sql_teb = text edit box(_sql)
),
hlistbox(
_cb = check box("Turn off subsequent debug output"),
_tb = text box(" "),
_bb = button box("OK",
is_checked = _cb << get(1);
if (is_checked,
global:g_log_execute_sql_debug = 0;
);
),
),
sql_teb << set nlines(40) << set width(500);
);
);
// OK we're good to go now.
batch interactive(1); // New 5-17-2018 force all errors to go to the log
_log_contents = log capture(
if (_invisible,
_dt = execute sql(_dbc, _sql, invisible, _tbl_name);
,
_dt = execute sql(_dbc, _sql, _tbl_name);
);
);
batch interactive(0); // New 5-17-2018 errors will not be forced to go to the log
// Check the log window for ODBC errors
// _log_contents = get log();
_found_error = 0;
crlf = hex to char("0D0A");
if (contains(_log_contents, "[Oracle][ODBC]") | contains(uppercase(_log_contents), "ERROR"), // Looking for errors
// then
_found_error = 1;
_log_list = words(_log_contents, crlf);
_error_msg = _log_list[1];
);
if (_found_error,
// then
// print(_sql); // Write the SQL out to the log window
_nw = new window("log_execute_sql: Oracle ODBC Error", << modal,
textbox("An Oracle error occurred in " || _caller || ": "),
panel box("Please email to technical support:",
sql_teb = text edit box(evalinsert(
"Calling Program: ^_caller^
Error Message: ^_error_msg^
SQL:
^_sql^"))),
sql_teb << set nlines(30) << set width(500),
);
);
// Return the table pointer
_dt;
); // end log_execute_sql
죄송합니다. 귀하의 질문을 잘못 읽었습니다.
Run Foreground 명령을 시도해 볼 수 있습니까?
Error_Msg = Log Capture( obj << run foreground );
안녕하세요 @jara95
당신의 답변에 감사드립니다
오류 메시지를 표시하기 위해 의도적으로 잘못된 SQL 문을 만들었습니다.
기존 데이터베이스를 고속으로 업데이트/확장하고 새 항목이 실제로 존재하는지 확인해야 합니다. 오류가 발생하면 오류 메시지(가장 좋은 경우는 SQL에서 얻은 메시지)로 사용자에게 경고해야 합니다. 해결 방법은 새 데이터 테이블을 열어 확인하고 다시 닫는 새 항목을 요청하는 두 번째 SQL 문을 만드는 것입니다.
이렇게 하려면 더 많은 시간이 필요하고 서버에 더 많은 "스트레스"를 가하며 무엇이 잘못되었는지에 대한 단서를 제공하지 않습니다.
나는 찾았다 꼬리 내용 = 로그 가져오기 ( - 5 ); 로그에 액세스하는 코드가 있지만 메시지에 여전히 액세스할 수 없습니다.
{""}<BR />Error running SQL Query:
[Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name '*table name*'. [SQLSTATE=42S02]캡처 로그와 마찬가지로 로그 파일에서도 {""}만 가져옵니다. 전체를 읽어도 로그 가져오기 ();
사용자 정의 SQL 인수 뒤에 여는 괄호가 누락된 것 같습니다.
업데이트 후 오류 메시지가 "테이블"을 참조하는 것 같습니다. 그게 실제 이름인가요, 아니면 이름이 저장되는 변수인가요? 그리고 SQL에서는 테이블 이름을 인용해야 하나요?