-
Notifications
You must be signed in to change notification settings - Fork 1
/
README
191 lines (146 loc) · 5.76 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
README
[Install Guide]
1. Check PSModulePath
C:\PS>$env:PSModulePath -split ";"
C:\Users\UserName\Documents\WindowsPowerShell\Modules
C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
2. Copy MdbCommand Folder
C:\Users\UserName\Documents\WindowsPowerShell\Modules\MdbCommand
if using 64bitOS: run with WOW64(32bit) powershell
[MdbCommand Exsamples]
C:\PS>ipmo MdbCommand
C:\PS>Open-Mdb newsample.mdb -Create
C:\PS>Invoke-Mdb 'Create Table table1 (a int not null constraint PK Primary Key, b varchar,
c yesno)'
C:\PS>invoke-mdb 'create table table2 (ID counter not null primary key, a int, b int)'
C:\PS>invoke-mdb @'
create table table3
(
col1 string(5),
col2 string(5),
a int,
constraint PK_table3 primary key (col1, col2)
)
'@
C:\PS>Get-Mdb
DatabaseName State Transaction DataSource
------------ ----- ----------- ----------
main Open No C:\scripts\ps1\newsample.mdb
C:\PS>Get-MdbTable
TableName TableType Description
--------- --------- -----------
table1 TABLE
table2 TABLE
table3 TABLE
C:\PS>Get-MdbColumn -TableName table1|ft -auto
TableName Pos ColumnName DataType AliasType Size NotNull Default PKey AutoInc
--------- --- ---------- -------- --------- ---- ------- ------- ---- -------
table1 1 a INTEGER int YES YES
table1 2 b VARCHAR string 255
table1 3 c BIT yesno YES
C:\PS>Get-MdbIndex |ft -auto
TableName IndexName Primary Unique Position ColumnName Collation
--------- --------- ------- ------ -------- ---------- ---------
table1 PK YES YES 1 a ASC
table2 Index_7BC68A99_2CED_49DE YES YES 1 ID ASC
table3 PK_table3 YES YES 1 col1 ASC
table3 PK_table3 YES YES 2 col2 ASC
C:\PS>$list = new-object collections.arraylist
C:\PS>$list.add(@(1,'colb1', $true))
C:\PS>$list.add(@(2,'colb2', $false))
C:\PS>$list.add(@(3,'colb3', $true))
C:\PS>Invoke-MdbBatch 'Insert Into table1 (a, b, c) Values (?, ?, ?)' $list
C:\PS>${MdbCommand.BatchTotalRecordsAffected}
3
C:\PS>Add-MdbQuery InsertTable1 'Insert Into Table1 (a, b, c) Values (?, ?, ?)'
C:\PS>Get-MdbQuery | ft -wrap
QueryName QueryType SQL
--------- --------- ---
InsertTable1 ACTION INSERT INTO Table1 ( a, b, c )
C:\PS>Invoke-MdbQuery InsertTable1 -Value 4,'colb4',$false
C:\PS>Invoke-Mdb 'Select a, b, c From table1 Where a > ?' 1 | ft -auto
a b c
- - -
2 colb2 False
3 colb3 True
4 colb4 False
C:\PS>try
>> {
>> Start-MdbTransaction
>>
>> Invoke-Mdb "Update table1 Set b = 'colb_change' Where a = 1"
>>
>> # processing
>>
>> Complete-MdbTransaction
>> }
>> catch
>> {
>> Write-Warning "$_"
>> Undo-MdbTransaction
>> }
C:\PS>Start-MdbConsole
mdb> select * from table1
...> /
a b c
- - -
1 colb1 True
2 colb2 False
3 colb3 True
4 colb4 False
mdb> .show
autosize : on
echo : off
headers : on
nullvalue : ""
width :
wrap : on
mdb>
mdb> .help
.autosize ON|OFF Like Format-Table AutoSize parameter
.begin Start transaction
.columns ?TABLE? List columns
.commit Commit transaction
.databases Show database Info
.echo ON|OFF Turn command echo on or off
.exit Exit this console
.headers ON|OFF Turn display of headers on or off
.help Show this message
.indices ?T? ?C? ?I? List indices
.nullvalue STRING Print STRING in place of NULL values
.quit Exit this console
.rollback Rollback transaction
.show Show the current values for various settings
.tables ?TABLE? List tables
.views ?VIEW? List querys and procedures
.width NUM1 NUM2 ... Set column widths (If ".width" Then clear widths)
.wrap ON|OFF Like Format-Table Wrap parameter
; or / or GO Enter SQL statements terminated
mdb>
mdb> .quit
C:\PS>
C:\PS>Use-MdbAliasCommand -Prefix mdb-
C:\PS>get-alias mdb-*
CommandType Name Definition
----------- ---- ----------
Alias mdb-begin Start-MdbTransaction
Alias mdb-close Close-Mdb
Alias mdb-columns Get-MdbColumn
.....................................
C:\PS>Use-MdbDotCommand
C:\PS>get-alias .*
CommandType Name Definition
----------- ---- ----------
Alias .begin Start-MdbTransaction
Alias .close Close-Mdb
Alias .columns Get-MdbColumn
Alias .commit Complete-MdbTransaction
Alias .console Start-MdbConsole
.....................................
C:\PS>Close-Mdb
C:\PS>.mdb sample1.mdb
C:\PS>.databases
C:\PS>.columns
C:\PS>.querys
C:\PS>.execute 'select * from table1'
C:\PS>.quit