Lets examine Hunter's oracle_export.bat Oracle Windows script. Note that he builds the exp parfile arguments into a DOS variable called %PARFILE%, just like
you can invoke Oracle directly from the DOS prompt (on one line only) : e.g.
c:> exp=%PARFILE%:
REM +--------------------------------------------------------------------------+
REM | VALIDATE COMMAND-LINE PARAMETERS |
REM +--------------------------------------------------------------------------+
if (%1)==() goto USAGE
if (%2)==() goto USAGE
if (%3)==() goto USAGE
REM +--------------------------------------------------------------------------+
REM | VALIDATE ENVIRONMENT VARIABLES |
REM +--------------------------------------------------------------------------+
REM set ORABACKUP=C:\oracle\orabackup\JEFFDB\export
REM set ORALOG=C:\oracle\custom\oracle\log
REM set ORATMP=C:\oracle\custom\oracle\temp
if (%ORALOG%)==() goto ENV_VARIABLES
if (%ORATMP%)==() goto ENV_VARIABLES
if (%ORABACKUP%)==() goto ENV_VARIABLES
REM +--------------------------------------------------------------------------+
REM | DECLARE ALL GLOBAL VARIABLES. |
REM +--------------------------------------------------------------------------+
set FILENAME=export_backup_online_full_9i
set DB_USERNAME=%1%
set DB_PASSWORD=%2%
set TNS_ALIAS=%3%
set PARFILE=%ORATMP%\%FILENAME%_%TNS_ALIAS%.parfile
set LOGFILE=%ORALOG%\%FILENAME%_%TNS_ALIAS%.log
set DUMPFILE=%ORABACKUP%\exp_full_%TNS_ALIAS%.dmp
REM +--------------------------------------------------------------------------+
REM | REMOVE OLD LOG AND PARAMETER FILE(S). |
REM +--------------------------------------------------------------------------+
del /q %PARFILE%
del /q %LOGFILE%
REM +--------------------------------------------------------------------------+
REM | WRITE EXPORT PARAMETER FILE. |
REM +--------------------------------------------------------------------------+
echo userid=%DB_USERNAME%/%DB_PASSWORD%@%TNS_ALIAS% > %PARFILE%
echo buffer=50000000 >> %PARFILE%
echo file=%DUMPFILE% >> %PARFILE%
echo compress=n >> %PARFILE%
echo grants=y >> %PARFILE%
echo indexes=y >> %PARFILE%
echo direct=no >> %PARFILE%
echo log=%LOGFILE% >> %PARFILE%
echo rows=y >> %PARFILE%
echo consistent=y >> %PARFILE%
echo full=y >> %PARFILE%
REM echo owner=(SCOTT) >> %PARFILE%
REM echo tables=(EMP, DEPT) >> %PARFILE%
echo triggers=y >> %PARFILE%
echo statistics=none >> %PARFILE%
echo constraints=y >> %PARFILE%
REM +--------------------------------------------------------------------------+
REM | MOVE OLD EXPORT (DUMP) FILE. |
REM +--------------------------------------------------------------------------+
del /q %DUMPFILE%.backup
move %DUMPFILE% %DUMPFILE%.backup
REM +--------------------------------------------------------------------------+
REM | PERFORM EXPORT. |
REM +--------------------------------------------------------------------------+
exp parfile=%PARFILE%
REM +--------------------------------------------------------------------------+
REM | SCAN THE EXPORT LOGFILE FOR ERRORS. |
REM +--------------------------------------------------------------------------+
echo ...
echo Analyzing log file for EXP- errors...
findstr /I /C:"EXP-" %LOGFILE%
if errorlevel 0 if not errorlevel 1 echo EXP- Errors: %FILENAME% %TNS_ALIAS% %COMPUTERNAME% %DATE% %TIME% %LOGFILE%
echo ...
echo Analyzing log file for ORA- errors...
findstr /I /C:"ORA-" %LOGFILE%
if errorlevel 0 if not errorlevel 1 echo ORA- Errors: %FILENAME% %TNS_ALIAS% %COMPUTERNAME% %DATE% %TIME% %LOGFILE%
echo ...
echo Analyzing log file for warnings...
findstr /I /C:"Export terminated successfully with warnings" %LOGFILE%
if errorlevel 0 if not errorlevel 1 echo WARNING: %FILENAME% %TNS_ALIAS% %COMPUTERNAME% %DATE% %TIME% %LOGFILE%
echo ...
echo Analyzing log file for errors...
findstr /I /C:"Export terminated unsuccessfully" %LOGFILE%
if errorlevel 0 if not errorlevel 1 echo ERROR: %FILENAME% %TNS_ALIAS% %COMPUTERNAME% %DATE% %TIME% %LOGFILE%
echo ...
echo END OF FILE REPORT
echo Filename : %FILENAME%
echo Database : %TNS_ALIAS%
echo Hostname : %COMPUTERNAME%
echo Date : %DATE%
echo Time : %TIME%
echo EXP Log File : %LOGFILE%
重点在SCAN THE EXPORT LOGFILE FROM ERRORS里面,看到了有这样一些判断IF ERRORLEVEL,这个就是判断是是否正确导出的标志,在MOS里面看到这样一些描述:
A. Successful export/import.
-------------------------
Result : Export terminated successfully without warnings
Import terminated successfully without warnings
Exit Code : EX_SUCC
Exit Level: 0
NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
添加数据到 user defaults:
[accountDefaults setObject:nameField.text forKey:UserDefaultNameKey];
也可以添加基本数据类型int, float, bool等,有相应得方法
[accountDefaults setBool:YES forKey:UserDefaultBoolKey];
从user defaults中获取数据:
[accountDefaults objectForKey:NCUserDefaultNameKey] [accountDefaults boolForKey: UserDefaultBoolKey];
要点:
NSUserDefaults非常好用,并不需要用户在程序中设置NSUserDefaults的全局变量,需要在哪里使用NSUserDefaults的数据,那么就在哪里创建一个NSUserDefaults对象,然后进行读或者写操作。
针对同一个关键字对应的对象或者数据,可以对它进行重写,重写之后关键字就对应新的对象或者数据,旧的对象或者数据会被自动清理。
以下是一个我自己写的例子,通过checkBtn按钮进行保存用户名和密码:
图片一:保存数据之前;或者上一次没有保存数据,第二次启动的界面
图片二:保存了数据,第二次打开所看到的启动初始界面
- (void)defaultCheck:(id)sender { NSLog(@" check按钮被按下 "); NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults]; if ([accountDefaults boolForKey:NCUserDefaultBoolForRegister] == NO) { ((UIButton*)sender).selected = YES; [accountDefaults setBool:YES forKey:NCUserDefaultBoolForRegister]; [accountDefaults setObject:nameField.text forKey:NCUserDefaultNameKey]; [accountDefaults setObject:pwdField.text forKey:NCUserDefaultPasswordKey]; } else {//YES ((UIButton*)sender).selected = NO; [accountDefaults setBool:NO forKey:NCUserDefaultBoolForRegister]; [accountDefaults setObject:nil forKey:NCUserDefaultNameKey]; [accountDefaults setObject:nil forKey:NCUserDefaultPasswordKey]; } } - (void)loadView { [super loadView]; nameField = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, 100, 30)]; pwdField = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, 100, 30)]; [nameField setCenter:CGPointMake(160, 100)]; [pwdField setCenter:CGPointMake(160, 150)]; NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults]; //存的是bool值一定要用boolForKey:获取 //如果之前已经保存了User Defaults,那么在读取的时候就要将数据读取出来,显示在用户名和密码框中(
这个问题Effective STL中有讲过,但当时没怎么留意。今天编程时由于涉及到输出的效率,所以做了一测试。
测试对象:
1.cout<<
2.ostream_iterator
3.ostreambuf_iterator
4.printf
5.cout.put
6.rdbuf()->sputn
测试平台:
1.6GHz处理器
测试代码:
#include <iostream> #include <iterator> #include <cstdio> #include <ctime> #include <iomanip> using namespace std; int main() { /*以10000个'a'作为输出目标*/ char a[10000] = {'a'}; clock_t start1, end1, start2, end2, start3, end3, start4, end4, start5, end5, start6, end6; /*测试ostream_iterator*/ start1 = clock(); copy(a, a + 10000, ostream_iterator<char>(cout)); end1 = clock(); /*测试ostreambuf_iterator*/ start2 = clock(); copy(a, a + 10000, ostreambuf_iterator<char>(cout)); end2 = clock(); /*测试cout<<*/ start3 = clock(); for (char x: a) cout << x; end3 = clock(); /*测试printf*/ start4 = clock(); for (char x: a) printf("%c", x); end4 = clock(); /*测试cout.put*/ start5 = clock(); for (char x: a) cout.put(x); end5 = clock(); /*测试rdbuf()->sputn*/ start6 = clock(); cout.rdbuf()->sputn(a, 10000); end6 = clock(); cout << endl; cout << setw(25) << "ostream_iterator: " << static_cast<double>(end1 - start1) / CLOCKS_PER_SEC << " seconds"<< endl; cout << setw(25) << "ostreambuf_iterator: " << static_cast<double>(end2 - start2) / CLOCKS_PER_SEC << " seconds"<< endl; cout << setw(25) << "cout<<: " << static_cast<double>(end3 - start3) / CLOCKS_PER_SEC << " seconds"<< endl; cout << setw(25) << "printf: " << static_cast<double>(end4 - start4) / CLOCKS_PER_SEC << " seconds"<< endl; cout << setw(25) << "cout.put: " << static_cast<double>(end5 - start5) / CLOCKS_PER_SEC << " seconds"<< endl; cout << setw(25) << "rdbuf()->sputn: " << static_cast<double>(end6 - start6) / CLOCKS_PER_SEC << " seconds"<< endl; return 0; }
测试结果:
1.用MinGW编译
ostream_iterator:
6.806 seconds
ostreambuf_iterator:
0.142 seconds
cout<<:
6.712 seconds
printf:
7.173 seconds
cout.put:
6.652 seconds
rdbuf()->sputn:
0.118 seconds
2.用Borland C++编译
ostream_iterator: 5.569 seconds ostreambuf_iterator: 0.203 seconds cout<<: 4.789 seconds printf: 4.493 seconds cout.put: 4.555 seconds rdbuf()->sputn: 0.141 seconds
3.用VS2012编译
ostream_iterator:
4.809 seconds
ostreambuf_iterator:
4.659
seconds
cout<<