News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

how to update table in masm32?

Started by elmo, December 19, 2010, 03:52:14 AM

Previous topic - Next topic

elmo

from KetilO, Now I can show all Tables in database  from the following code

Code1:

invoke SQLAllocHandle,SQL_HANDLE_STMT,hConn,addr hStmt
.if ax==SQL_SUCCESS || ax==SQL_SUCCESS_WITH_INFO
invoke SQLTables,hStmt,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
.if ax==SQL_SUCCESS || ax==SQL_SUCCESS_WITH_INFO
.while TRUE
invoke SQLBindCol,hStmt,3,SQL_C_CHAR,addr TheTableName,sizeof TheTableName,addr hTableName
invoke SQLBindCol,hStmt,4,SQL_C_CHAR,addr TheTableType,sizeof TheTableType,addr hTableType
invoke SQLFetch,hStmt
.if ax==SQL_SUCCESS || ax==SQL_SUCCESS_WITH_INFO
invoke lstrcmp,addr TheTableType,SADD("TABLE")
.if !eax
invoke SendMessage,hCombo1,CB_ADDSTRING, 0,ADDR TheTableName
.endif
;lea edi,[edi+sizeof SQLTABLE]
.else
.break
.endif
.endw
.else
invoke MessageBox,hWin,SADD("Unable to get tables"),SADD("Alert"),0
.endif
invoke SQLFreeHandle,SQL_HANDLE_STMT,hStmt
.else
invoke MessageBox,hWin,SADD("Unable to allocate statement handle"),SADD("Alert"),0
.endif






I can show all columns of the selected tables in database from the following code
Code2:


mov edi,0
invoke SQLAllocHandle,SQL_HANDLE_STMT,hConn,addr hStmt
.if ax==SQL_SUCCESS || ax==SQL_SUCCESS_WITH_INFO
invoke SQLAllocHandle,SQL_HANDLE_STMT,hConn2,addr hStmt2
.if ax==SQL_SUCCESS || ax==SQL_SUCCESS_WITH_INFO
szText Query,"SELECT * FROM Table1"
invoke SQLExecDirect, hStmt2,addr Query,sizeof Query


.if ax==SQL_SUCCESS || ax==SQL_SUCCESS_WITH_INFO
invoke GetWindowText,hCombo1,addr STRCombo1,256
invoke szLen,addr STRCombo1
invoke SQLColumns,hStmt,NULL,NULL,NULL,NULL,ADDR STRCombo5,eax,NULL,NULL

.if ax==SQL_SUCCESS || ax==SQL_SUCCESS_WITH_INFO
.while edi<100
invoke SQLBindCol,hStmt,4,SQL_CHAR,addr TheColumnName,sizeof TheColumnName,addr hColumnName
invoke SQLBindCol,hStmt,6,SQL_CHAR,addr TheColumnType,sizeof TheColumnType,addr hColumnType
invoke SQLBindCol,hStmt,7,SQL_CHAR,addr TheColumnWidth,sizeof TheColumnWidth,addr hColumnWidth
invoke SQLFetch,hStmt

.if ax==SQL_SUCCESS || ax==SQL_SUCCESS_WITH_INFO
;ROW ID
mov lvi.imask,LVIF_PARAM
push edi
pop lvi.iItem
mov lvi.iSubItem,0
push edi
pop lvi.lParam
invoke SendMessage,hList2,LVM_INSERTITEM,0,addr lvi


;COLUMN NAME
mov lvi.imask,LVIF_TEXT
mov lvi.iSubItem,0
lea eax,TheColumnName
mov lvi.pszText,eax
invoke SendMessage,hList2,LVM_SETITEM,0,addr lvi

;COLUMN TYPE
mov lvi.imask,LVIF_TEXT
inc lvi.iSubItem
lea eax,TheColumnType
mov lvi.pszText,eax
invoke SendMessage,hList2,LVM_SETITEM,0,addr lvi

;COLUMN WIDTH
mov lvi.imask,LVIF_TEXT
inc lvi.iSubItem
lea eax,TheColumnWidth
mov lvi.pszText,eax
invoke SendMessage,hList2,LVM_SETITEM,0,addr lvi

inc edi
.else
.break
.endif
.endw
.else
invoke MessageBox,hWin,SADD("Unable to get columns"),SADD("Alert"),0
.endif
.else
invoke MessageBox,hWin,SADD("Failed to execute query"),SADD("Alert"),0
.endif
invoke SQLCloseCursor, hStmt2
invoke SQLFreeHandle,SQL_HANDLE_STMT,hStmt2
.else
invoke MessageBox,hWin,SADD("Unable to allocate statement handle"),SADD("Alert"),0
.endif
invoke SQLCloseCursor, hStmt
invoke SQLFreeHandle,SQL_HANDLE_STMT,hStmt
.else
invoke MessageBox,hWin,SADD("Unable to allocate statement handle"),SADD("Alert"),0
.endif
ret






From Code2, I can only show ColumnName/ ColumnType/ ColumnWidth.
I want to do 2 following actions:
1. I want to show what column who be the PrimaryKey of the selected table.
2. I want to change Column Name / Column Type / Column Width of the selected table.
Could you give me a link or some code to solve those problems?
Thank you...
be the king of accounting programmer world!