xiaoxing tech

August 30, 2007

Use "SQL" to Create database

Filed under: vb.net — xiaoxing @ 3:03 pm
Function CreateDatabase()Function CreateDatabase(ByVal sDBName As String, ByVal sPath As String, Optional ByVal sDataSize As String = "2", Optional ByVal sMaxDataSize As String = "10", Optional ByVal sLogSize As String = "1", Optional ByVal sMaxLogSize As String = "5", Optional ByVal sGrowth As String = "10", Optional ByVal auto_shrink As Boolean = False, Optional ByVal auto_update_statistics As Boolean = True, Optional ByVal auto_close As Boolean = False, Optional ByVal auto_create_statistics As Boolean = True) As Boolean
Dim str As String
Dim db_option1 As String = "sp_dboption ‘" & sDBName & "‘, autoshrink, true"
Dim db_option2 As String = "sp_dboption ‘" & sDBName & "‘, ‘auto update statistics’, false"
Try
Select Case guInternal.DBTypeSelected
Case enumDBTYPE.MSSQLServer
str = "CREATE DATABASE MyDatabase ON PRIMARY (NAME = MyDatabase_Data, FILENAME = ‘C:\\MyDatabaseData.mdf’, SIZE = 2MB, MAXSIZE = 10MB, FILEGROWTH = 10%) LOG ON (NAME = MyDatabase_Log, FILENAME = ‘C:\\MyDatabaseLog.ldf’, SIZE = 1MB, MAXSIZE = 5MB, FILEGROWTH = 10%)"
str = "CREATE DATABASE " & sDBName & " ON PRIMARY (NAME = " & sDBName & "_Data, FILENAME = ‘" & sPath & sDBName & "Data.mdf’, SIZE = " & sDataSize & "MB, MAXSIZE = " & sMaxDataSize & "MB, FILEGROWTH = " & sGrowth & "%) LOG ON (NAME = " & sDBName & "_Log, FILENAME = ‘" & sPath & sDBName & "Log.ldf’, SIZE = " & sLogSize & "MB, MAXSIZE = " & sMaxLogSize & "MB, FILEGROWTH = " & sGrowth & "%)"

Dim objDB As New clsCMDBObject
With objDB
Specific parameters for execution
.ExecuteAsync = False
.DataTypeReturn
= clsCMDBObject.enumDB_OBJECT_RETURN_TYPE.NoData
Command object definition
.Command.CommandType = CommandType.Text
.Command.CommandText
= str
If ExecuteDBObject(objDB) = True Then
Execution done without errors
Console.WriteLine("DataBase is Created Successfully")
objCMDataTable.LoadFromDataTable(objDB.DataTable(0))
End If
objDB.Dispose()
End With
objDB
= Nothing

If auto_shrink <> False Then
objDB
= New clsCMDBObject
With objDB
Specific parameters for execution
.ExecuteAsync = False
.DataTypeReturn
= clsCMDBObject.enumDB_OBJECT_RETURN_TYPE.NoData
Command object definition
.Command.CommandType = CommandType.Text
.Command.CommandText
= db_option1
If ExecuteDBObject(objDB) = True Then
Execution done without errors
End If
objDB.Dispose()
End With
objDB
= Nothing
End If

If auto_update_statistics <> True Then
objDB
= New clsCMDBObject
With objDB
Specific parameters for execution
.ExecuteAsync = False
.DataTypeReturn
= clsCMDBObject.enumDB_OBJECT_RETURN_TYPE.NoData
Command object definition
.Command.CommandType = CommandType.Text
.Command.CommandText
= db_option2
If ExecuteDBObject(objDB) = True Then
Execution done without errors
End If
objDB.Dispose()
End With
objDB
= Nothing
End If


CreateDatabase
= True



Case enumDBTYPE.Oracle

Case enumDBTYPE.DB2
Case enumDBTYPE.AS400
Case 0 in this case the method "openDatabase" is not called, so the DBType is not selected
Throw New ApplicationException("Please call ""OpenDatabase"" first to create an active connection.")
End Select

Catch ex As Exception
CreateDatabase
= False
MessageBox.Show(ex.ToString(), "MyProgram", MessageBoxButtons.OK, MessageBoxIcon.Information)
If ex.Message = "Database ‘" & sDBName & "‘ already exists." Then
Call CatchError("The database being created, exists on the current server.")
ElseIf ex.Message = "The ConnectionString property has not been initialized." Then
Call CatchError("Trying to create a database on a disconnected server.")
ElseIf guInternal.DBTypeSelected = 0 Then
Console.WriteLine(ex.Message
& " ::ex.Message")
Call CatchError(ex.Message)
End If

End Try
End Function

August 29, 2007

Use "SQL" to retrieve database information

Filed under: vb.net — xiaoxing @ 4:47 pm

‘use one sql statement to retrieve lots of information. so, declare a table array
Dim tables() As clsCMDataTable
tables = currentCMDB.RetrieveDBProperties(selectedDBName)
If tables Is Nothing Then
    Me.Close()
    Exit Sub
End If

‘the location of each property is fixed
tbtDbsize.Text = “Owner”
tbtDbsize.VirtualTextBox.Text = tables(0).Rows(0)(2)
tbtDbsize.Enabled = False

tbtDbmaxsize.Text = “Date created”
tbtDbmaxsize.VirtualTextBox.Text = tables(0).Rows(0)(4)
tbtDbmaxsize.Enabled = False

tbtLogsize.Text = “Size”
tbtLogsize.VirtualTextBox.Text = tables(0).Rows(0)(1)
tbtLogsize.Enabled = False

tbtLogmaxsize.Text = “Space available” http://supportcentral.ge.com/blog/sup_personal_post_comment.asp?person_id=1609810&post_id=48064
tbtLogmaxsize.VirtualTextBox.Text = tables(2).Rows(0)(2)
tbtLogmaxsize.Enabled = False

tbtGrowth.Text = “Grow”
Dim growFromDB As String
growFromDB = CStr(tables(1).Rows(0)(6)).Trim
If growFromDB.EndsWith(“B”) Then
    tbtGrowth.Enabled = False
End If
tbtGrowth.VirtualTextBox.Text = growFromDB

tbtPath.Text = “File Location”
tbtPath.VirtualTextBox.Text = tables(1).Rows(0)(2)
tbtPath.Enabled = False

Dim autoShrinkFromDB As Boolean
Dim autoUpdateStatFromDB As Boolean
autoShrinkFromDB = currentCMDB.AutoShrink(selectedDBName)
CheckBoxNode1.Checked = autoShrinkFromDB
autoUpdateStatFromDB = currentCMDB.AutoUpdateStatistics(selectedDBName)
CheckBoxNode2.Checked = autoUpdateStatFromDB

August 28, 2007

use of: clsCMDataTable

Filed under: vb.net — xiaoxing @ 4:46 pm

Dim oServers As New clsCMDataTable

‘in form load sub
oServers.AddColumnDefinition(“ID”, TypeCode.Int32, clsCMDataTable.enumENCRYPTION_MODE.None, True, True, True, False, False)
oServers.AddColumnDefinition(“ServerName”, TypeCode.String)
oServers.AddColumnDefinition(“Status”, TypeCode.Int32)
oServers.AddColumnDefinition(“CMDatabase”, TypeCode.Object)

‘add rows; REMEMBER: YOU Should add multiple CELLS for one row in one line of code!!
With oServers
        .AddLineWithValues(“ServerName”, sServerName, “ServerCapacity”, iServerCapacity)
        .SaveInFile(sServersFile, clsCMConstants.enumFileFormat.Normal)
End With

‘retrieve values from the table
With oServers
  If .CountOfLines <> 0 Then
    Dim i As Int32
    For i = 0 To .CountOfLines – 1
      Dim sServer As String = .GetColumnValue(i, “ServerName”)
     grpServers.Items.AddRange(New Xceed.SmartUI.Controls.TreeView.Node() {CreateNode(sServer)})
      grpServers.Items(i).Key = .GetColumnValue(i, “ServerName”)
    Next
    pnlServer.Text = grpServers.Items(0).Text 
    pnlServer.Key = grpServers.Items(0).Key  
  End If
End With

‘in other sub
Dim theRow As DataRow = oServers.GetUniqueDataRow(“ServerName=’” & pnlServer.Text & “‘”)

‘remove
With oServers
               .RemoveLines(“ServerName=’” & sServerName & “‘”)
               .SaveInFile(sServersFile, clsCMConstants.enumFileFormat.Normal)
End With

August 27, 2007

Multidimensional Arrays

Filed under: vb.net — xiaoxing @ 2:42 pm

image

The value “gamma” is referenced by Letters(2,0); the value “e” is referenced by Letters(4,1).

Declaring Arrays

a multidimensional array commas are used for each additional column

Dim Letters(,) As String
Initializing Arrays
Dim Letters() As String = {"alpha","beta","gamma","delta","epsilon"}
Dim Letters(,) As String = { {"alpha","a"},{"beta","b"},{"gamma","c"},{"delta","d"},{"epsilon","e"} }

Imports System
Public Class MainClass
Shared Sub Main()
Const rowsUB As Integer = 4
Const columnsUB As Integer = 3
Dim rectangularArray(rowsUB, columnsUB) As Integer
'populate the array
Dim As Integer
For i = 0 To rowsUB - 1
Dim As Integer
For j = 0 To columnsUB - 1
rectangularArray(i, j) = i + j
Next j
Next i
'report the contents of the array
For i = 0 To rowsUB - 1
Dim As Integer
For j = 0 To columnsUB - 1
Console.WriteLine( _
"rectangularArray[{0},{1}] = {2}", _
i, j, rectangularArray(i, j))
Next j
Next i
End Sub
End Class

August 16, 2007

faind: cmd tool, to locate the file that contains content we are searching

Filed under: tool — xiaoxing @ 1:57 pm

Windows’s “Ctrl+E” search dog is lame.
Then I try Google Desktop. It’s indexing seems never end, and it doesn’t search for content within a folder. So, I have to look for another tool.

faind, is a good command line tool, a tool not easy to use, but works.
http://solarix.ru/for_users/download_them/faind/faind-en.shtml

1. download “φaind for Windows” (faind-setup-pro.exe 4029kb) from http://solarix.ru/for_users/map/map-en.shtml
xiaoxingz aug 16, 2007 txt

2. install it: C:\Program Files\Bulldozer.Win32

3. make a bat file contains:
“C:\Program Files\Bulldozer.Win32\faind.exe” %1 %2 %3 %4 %5 %6 %7 %8 %9
put the file here: C:\Program Files\Java\jdk1.6.0_02\bin
save as name: faind.bat

4. create a text file: faindCommands.txt
put it in the “Start -  Programs”
put commonly used faind commands and DOS commands here.

5. use cases:
Open cmd window.
Use cls to clear the window.
Use cd to go to the folder.

a. The basic function of this program is to search files for text (usually lines or sentences) that contain certain patterns. The following example performs the search for very first occurrence of single word “cat” in one file 501140729-LAC-PREP222.txt, morphology is disabled:
faind 501140729-LAC-PREP222.txt -sample “PSAMER”

b. The next example is nearly the same as above, but all files in current folder are scanned:
faind . -sample “PSAMER”

the result:
Aug. 16Screen_15

This result says that within the current folder, there are two files that contain “PSAMER”. They are:
.\20070716\CN=Gerardo Ruben Garlog.html
and
.\20070719\CN=Gerardo Ruben Garlog.html

(to copy selected content from the cmd window, simply key “Enter”)

c. Searching for pattern “white cat” in the single file a.txt with morphology engine enabled:
faind a.txt  -wordforms -distance=s -minbound=1 -sample “white cat

Here: 1. the option -wordforms lets the program to find also the plural forms like “white cats“.
          2. -distance=s requires that all words of pattern to be in one sentence.
          3. -minbound=1 requites that all words of query pattern must be found. Otherwise, too frequent and meaningless words (like artictes) can be omitted.
         4. Options -ordered is not set so contexts like “cat is white” can also be matched.

reference:
http://solarix.ru/for_users/download_them/faind/samples-en.shtml


 

 

August 13, 2007

JSP – Servlet day 4

Filed under: JSP — xiaoxing @ 2:59 pm

Servlet (java class) can also generate HTML pages. 
First write the servlet class.
Then, map the servlet class:
image

Then in index file, put:

<jsp:forward page=”/ServletTemplate”/>

 

Blog at WordPress.com.