Oracle 用 CSV 出力スクリプト作成


  oraclecsv.php




送信ボタンをクリックすると、スクリプト(VBScript)のダウンロードになります。
自分のサイトに置くのであれば、ダウンロードせずにそのまま「開く」で実行します



  

<?
if ( $_POST['pcname'] != '' ) {
	session_start();
	setcookie("pcname", $_POST['pcname'], time()+3600*24*30);
	setcookie("service", $_POST['service'], time()+3600*24*30);
	setcookie("user", $_POST['user'], time()+3600*24*30);
	setcookie("pass", $_POST['pass'], time()+3600*24*30);
	setcookie("table", $_POST['table'], time()+3600*24*30);
	$_POST['path'] = trim(str_replace("\\\\","\\", $_POST['path']));
	setcookie("path", $_POST['path'], time()+3600*24*30);
	if ( trim( $_POST['service'] ) != "" ) {
		$_POST['service'] = '/' . $_POST['service'];
	}
	$str = <<<VBS
' **********************************************************
' オブジェクト作成
' **********************************************************
Set Cn = CreateObject( "ADODB.Connection" )
Set Rs = CreateObject( "ADODB.Recordset" )
Set Fs = CreateObject( "Scripting.FileSystemObject" )

strDriver = "{Microsoft ODBC for Oracle}"
strServer = "{$_POST['pcname']}{$_POST['service']}"
strUser = "{$_POST['user']}"
strPass = "{$_POST['pass']}"

strTable = "{$_POST['table']}"

ConnectionString = _
	"Provider=MSDASQL" & _
	";Driver=" & strDriver & _
	";Server=" & strServer & _
	";UID=" & strUser & _ 
	";PWD=" & strPass & _ 
	";" 

' **********************************************************
' 接続
' **********************************************************
on error resume next
Cn.Open ConnectionString
if Err.Number <> 0 then
	Wscript.Echo Err.Description
	Wscript.Quit
end if
on error goto 0

' **********************************************************
' 列情報取得
' **********************************************************
Query = "select * from USER_TAB_COLUMNS"
Query = Query & " where TABLE_NAME = '" & strTable & "'"
Query = Query & " order by COLUMN_ID"

on error resume next
Rs.Open Query, Cn
if Err.Number <> 0 then
	Cn.Close
	Wscript.Echo Err.Description
	Wscript.Quit
end if
on error goto 0

Query = "select "
CsvTitle = ""
Do While not Rs.EOF
	if CsvTitle <> "" then
		Query = Query & "||','||"
		CsvTitle = CsvTitle & ","
	end if
	Query = Query & Rs.Fields("COLUMN_NAME").Value
	CsvTitle = CsvTitle & Rs.Fields("COLUMN_NAME").Value
	Rs.MoveNext
Loop
Query = Query & " from " & strTable
Rs.Close

' **********************************************************
' データ取得用クエリー
' **********************************************************
on error resume next
Rs.Open Query, Cn
if Err.Number <> 0 then
	Cn.Close
	Wscript.Echo Err.Description
	Wscript.Quit
end if
on error goto 0

' **********************************************************
' 出力ファイルオープン
' **********************************************************
Set Csv = Fs.CreateTextFile( "{$_POST['path']}", True )

' **********************************************************
' タイトル出力
' **********************************************************
Csv.WriteLine CsvTitle

' **********************************************************
' データ出力
' **********************************************************
Do While not Rs.EOF
	Csv.WriteLine Rs.Fields(0).Value
	Rs.MoveNext
Loop

' **********************************************************
' ファイルクローズ
' **********************************************************
Csv.Close

' **********************************************************
' レコードセットクローズ
' **********************************************************
Rs.Close

' **********************************************************
' 接続解除
' **********************************************************
Cn.Close

' **********************************************************
' オブジェクト解放
' **********************************************************
Set Fs = Nothing
Set Rs = Nothing
Set Cn = Nothing

Wscript.Echo "処理が終了しました"

VBS;
$flname = "oraclecsv" . session_id() . ".vbs";
file_put_contents($flname,$str);
header( "Location: $flname" );
}
else {
	header( "Content-Type: text/html" );
	header( "Expires: Wed, 31 May 2000 14:59:58 GMT" );
	if ( $_COOKIE['service'] == "" ) {
		$_COOKIE['service'] = "ORCL";
	}
	if ( $_COOKIE['path'] != "" ) {
		$_COOKIE['path'] = trim(str_replace("\\\\","\\", $_COOKIE['path']));
	}
?>
<HTML>
<HEAD>
<META http-equiv="Content-type" content="text/html; charset=shift_jis" />
<STYLE type="text/css">
* {
	font-size: 12px;
}
.column {
	font-weight:bold;
	border-style:solid;
	border-width:1px;
	border-color:#000000;
	padding: 4px;
}
.head {
	background-color:#C0C0C0;
}
</STYLE>
<SCRIPT language="javascript" type="text/javascript">
function SetSavePath( obj ) {
	if ( document.getElementsByName("table")[0].value == "" ) {
		alert("テーブル名を入力して下さい")
		return;
	}
	var path = obj.value;
	var idx = path.lastIndexOf("\\");
	path = path.substring( 0, idx ) 
	document.getElementsByName("path")[0].value =
	 path + "\\" + 
	 document.getElementsByName("table")[0].value + ".csv";
}
</SCRIPT>
</HEAD>
<BODY>
<FORM
	method="POST"
>
<TABLE
	border=1
	style='
		border-collapse:collapse;
		border-style:solid;
		border-width:1px;
		border-color:#000000;
	'
>
<TR>
	<TD class="column head">PC名</TD>
	<TD class="column">
	<INPUT
		type="text"
		name="pcname"
		value="<?= $_COOKIE['pcname'] ?>"
		style='width:200px;'
	>&nbsp;&nbsp;サービス名
	<INPUT
		type="text"
		name="service"
		value="<?= $_COOKIE['service'] ?>"
		style='width:50px;'
	>&nbsp;&nbsp;
	</TD>
</TR>
<TR>
	<TD class="column head">ユーザー</TD>
	<TD class="column">
	<INPUT
		type="text"
		name="user"
		value="<?= $_COOKIE['user'] ?>"
		style='width:200px;'
	>&nbsp;&nbsp;
	</TD>
</TR>
<TR>
	<TD class="column head">パスワード</TD>
	<TD class="column">
	<INPUT
		type="password"
		name="pass"
		value="<?= $_COOKIE['pass'] ?>"
		style='width:200px;'
	>&nbsp;&nbsp;
	</TD>
</TR>
<TR>
	<TD class="column head">テーブル名</TD>
	<TD class="column">
	<INPUT
		type="text"
		name="table"
		value="<?= $_COOKIE['table'] ?>"
		style='width:400px;'
	>&nbsp;&nbsp;
	</TD>
</TR>
<TR>
	<TD class="column head">保存パス<br>仮参照</TD>
	<TD class="column">
	<INPUT
		type="file"
		name="pathdummy"
		style='width:500px;'
		onChange='SetSavePath(this);'
	><br>対象ディレクトリにあるファイルを参照して下さい
	</TD>
</TR>
<TR>
	<TD class="column head">保存パス</TD>
	<TD class="column">
	<INPUT
		type="text"
		name="path"
		value="<?= $_COOKIE['path'] ?>"
		style='width:500px;'
	>&nbsp;&nbsp;
	</TD>
</TR>

<TR>
	<TD class="column" colspan="2">
	<INPUT
		type="submit"
		name="send"
		value="送信"
	>
	</TD>
</TR>

</TABLE>
</FORM>
</BODY>
</HTML>
<?

	$DirHandle = @opendir("./");
	if ( $DirHandle ) {
		$Target = readdir( $DirHandle );
		while( $Target !== false ) {

			if ( $Target != "." ) {
				$ext = strrchr( $Target, "." );
				$ext = strtolower($ext);
				if ( $ext == ".vbs" ) {
					$astamp = stat($Target);
					$laststamp = $astamp[9];
					if ( $laststamp < time() - 300 ) {
						@unlink($Target);
					}
				}
			}
			$Target = readdir( $DirHandle );

		}
		
		closedir( $DirHandle );
	}


}
?>
  










yahoo  google  MSDN  MSDN(us)  WinFAQ  Win Howto  tohoho  ie_DHTML  vector  wdic  辞書  天気 


[phpVarious]
CCBot/2.0 (https://commoncrawl.org/faq/)
24/07/19 11:05:40
InfoBoard Version 1.00 : Language=Perl

1 BatchHelper COMprog CommonSpec Cprog CprogBase CprogSAMPLE CprogSTD CprogSTD2 CprogWinsock Cygwin GameScript HTML HTMLcss InstallShield InstallShieldFunc JScript JScriptSAMPLE Jsfuncs LLINK OldProg OracleGold OracleSilver PRO PRObrowser PROc PROconePOINT PROcontrol PROftpclient PROjscript PROmailer PROperl PROperlCHAT PROphp PROphpLesson PROphpLesson2 PROphpLesson3 PROphpfunction PROphpfunctionArray PROphpfunctionMisc PROphpfunctionString PROsql PROvb PROvbFunction PROvbString PROvbdbmtn PROvbonepoint PROwebapp PROwin1POINT PROwinSYSTEM PROwinYOROZU PROwindows ProjectBoard RealPHP ScriptAPP ScriptMaster VBRealtime Vsfuncs a1root access accreq adsi ajax amazon argus asp aspSample aspVarious aspdotnet aw2kinst cappvariety centura ckeyword classStyle cmaterial cmbin cmdbapp cmenum cmlang cmlistbox cmstd cmstdseed cmtxt cs daz3d db dbCommon dbaccess dnettool dos download flex2 flex3 flex4 framemtn framereq freeWorld freesoft gimp ginpro giodownload google hdml home hta htmlDom ie9svg install java javaSwing javascript jetsql jquery jsp jspTest jspVarious lightbox listasp listmsapi listmsie listmsiis listmsnt listmspatch listmsscript listmsvb listmsvc memo ms msde mysql netbeans oraPlsql oracle oracleWiper oraclehelper orafunc other panoramio pear perl personal pgdojo pgdojo_cal pgdojo_holiday pgdojo_idx pgdojo_ref pgdojo_req php phpVarious phpguide plsql postgres ps r205 realC realwebapp regex rgaki ruby rule sboard sc scprint scquest sdb sdbquest seesaa setup sh_Imagick sh_canvas sh_dotnet sh_google sh_tool sh_web shadowbox shgm shjquery shvbs shweb sjscript skadai skywalker smalltech sperl sqlq src systemdoc tcpip tegaki three toolbox twitter typeface usb useXML vb vbdb vbsfunc vbsguide vbsrc vpc wcsignup webanymind webappgen webclass webparts webtool webwsh win8 winofsql wmi work wp youtube