Presentasjon lastes. Vennligst vent

Presentasjon lastes. Vennligst vent

SQLHiA Kap 12 Dynamisk SQL. SQLHiA SQLHiA FlerbrukersystemClient / Server Database DBMS Application_2 SQL-Request Data Application_3 Application_1 ClientServer.

Liknende presentasjoner


Presentasjon om: "SQLHiA Kap 12 Dynamisk SQL. SQLHiA SQLHiA FlerbrukersystemClient / Server Database DBMS Application_2 SQL-Request Data Application_3 Application_1 ClientServer."— Utskrift av presentasjonen:

1 SQLHiA Kap 12 Dynamisk SQL

2 SQLHiA

3 SQLHiA FlerbrukersystemClient / Server Database DBMS Application_2 SQL-Request Data Application_3 Application_1 ClientServer

4 SQLHiA Resultatsett Database DBMS Application SQL-Request Data SELECT SNr, Navn, PNr FROM Selger WHERE PNr = 6400 SNrNavnPNr 5Nilsen5002 2Olsen6400 1Hansen9000 4Berg6400 Tabellen Selger SNrNavnPNr 2Olsen6400 4Berg6400 Resultatsett ClientServer Fetch RowID FetchThrough

5 SQLHiA RowID RowIDSNrNavnPNr CAAD5Nilsen5002 BACV2Olsen6400 ERCB1Hansen9000 EADD4Berg6400 Selger (ID = SNr) SNrNavnPNr 5Nilsen5002 2Olsen6400 1Hansen9000 4Berg6400 Selger (ID = SNr) Et eksempel på en 3NF-tabell Selger med tre kolonner SNr, Navn og PNr RowID er en ekstra kolonne i hver tabell som alltid kommer i tillegg til de kolonnene vi eksplisitt definerer. RowID er entydig for hver rad og fungerer som en slags identifikator.

6 SQLHiA

7 SQLHiA Statisk SQL SNrIDNavnPNr 5Nilsen5002 2Olsen6400 1Hansen9000 4Berg6400 Selger (ID = SNr) SNrID Navn PNr Select SELECT SNrID, Navn, PNr FROMSelger Set sSelect = ‘SELECT SNrID, Navn, PNr INTO :dfnSNrID, :dfsNavn, dfnPNr FROM Selger’ Call SqlPrepare ( hSql, sSelect ) Call SqlExecute ( hSql ) Call SqlFetchNext ( hSql, nFetch )

8 SQLHiA Statisk SQL SNrID Navn PNr Select SELECT SNrID, Navn, PNr FROMSelger SNrID Navn PNr 2 Select SELECT Navn, PNr FROMSelger WHERE SNrID = :dfnSNrID SNrID Navn PNr 6400 Select SELECT SNrID, Navn FROMSelger WHERE PNr = :dfnPNr SNrID Navn PNr Nilsen Select SELECT SNrID, PNr FROMSelger WHERE Navn = :dfsNavn SNrID Navn PNr Nilsen 6400 Select SELECT Navn, PNr FROMSelger WHERE Navn = :dfsNavn AND PNr = : dfnPNr SNrID Navn PNr %sen 6400 Select SELECT SNrID, Navn FROMSelger WHERE Navn LIKE ‘ || ‘\’’ || dfsNavn || ‘\’’ AND PNr = :dfnPNr

9 SQLHiA Fra Statisk SQL til Dynamisk SQL SNrID Navn PNr 6400 Select SELECT SNrID, Navn, PNr FROMSelger WHERE PNr = :dfnPNr Set sSelect = ‘SELECT SNrID, Navn, PNr INTO :dfnSNrID, :dfsNavn, dfnPNr FROM Selger WHERE PNr = :dfnPNr’ Set sSelect = ‘SELECT ‘ || sColumn || ‘ INTO ‘ || sInto || ‘ FROM ‘ || sFrom ‘ WHERE ‘ || sWhere frmSelger sColumn = ‘SNrID, Navn, PNr’ sInto = ‘ :dfnSNrID, :dfsNavn, :dfnPNr’ sFrom= ‘Selger’ sWhere= ‘PNr = :dfnPNr’

10 SQLHiA Dynamisk SQL-Initier SQL-variable SNrID Navn PNr 6400 Select frmSelger dfnSNrID dfsNavn dfnPNr pbSelect On SAM_Click Call SalSendMsg ( hWndForm, PAM_SELECT, 0, 0 ) frmSelger Message Actions On PAM_SELECT Set sColumn = ‘‘ Set sInto= ‘‘ Set sFrom= ‘‘ Set sWhere= ‘‘ Call SalSendMsg ( hWndForm, PAM_SQL, 0, 0 ) Call SalSendMsgToChildren ( hWndForm, PAM_SQL, 0, 0 ) 1 2

11 SQLHiA Dynamisk SQL-Bestem tabell-navn SNrID Navn PNr 6400 Select frmSelger dfnSNrID dfsNavn dfnPNr pbSelect frmSelger Message Actions On PAM_SELECT Set sColumn = ‘‘ Set sInto= ‘‘ Set sFrom= ‘’ Set sWhere= ‘‘ Call SalSendMsgTo ( hWndForm, PAM_SQL, 0, 0 ) Call SalSendMsgToChildren ( hWndForm, PAM_SQL, 0, 0 )... On PAM_SQL Call SalGetWindowText ( hWndForm, sWName, 20 ) sFrom = SalStrRight ( sWName, SalStrLength(sWName) - 3 ) sWName = ‘frmSelger’ sFrom = ‘Selger’

12 SQLHiA Dynamisk SQL-Bestem SQL-variable for dfnSNrID SNrID Navn PNr 6400 Select frmSelger dfnSNrID dfsNavn dfnPNr pbSelect frmSelger Message Actions On PAM_SELECT Set sColumn = ‘‘ Set sInto= ‘‘ Set sFrom= ‘’ Set sWhere= ‘‘ Call SalSendMsgTo ( hWndForm, PAM_SQL, 0, 0 ) Call SalSendMsgToChildren ( hWndForm, PAM_SQL, 0, 0 )... sColumn= ‘ SNrID ’ sInto= ‘ :dfnSNrID ’

13 SQLHiA Dynamisk SQL-Bestem SQL-variable for dfsNavn SNrID Navn PNr 6400 Select frmSelger dfnSNrID dfsNavn dfnPNr pbSelect frmSelger Message Actions On PAM_SELECT Set sColumn = ‘‘ Set sInto= ‘‘ Set sFrom= ‘’ Set sWhere= ‘‘ Call SalSendMsgTo ( hWndForm, PAM_SQL, 0, 0 ) Call SalSendMsgToChildren ( hWndForm, PAM_SQL, 0, 0 )... sColumn= sColumn || ‘, ‘ || ‘ Navn ’ = ‘ SNrID, Navn ‘ sInto= sInto || ‘ :dfsNavn ’ = ‘ :dfnSNrID, :dfsNavn ‘

14 SQLHiA Dynamisk SQL-Bestem SQL-variable for dfnPNr SNrID Navn PNr 6400 Select frmSelger dfnSNrID dfsNavn dfnPNr pbSelect frmSelger Message Actions On PAM_SELECT Set sColumn = ‘‘ Set sInto= ‘‘ Set sFrom= ‘’ Set sWhere= ‘‘ Call SalSendMsgTo ( hWndForm, PAM_SQL, 0, 0 ) Call SalSendMsgToChildren ( hWndForm, PAM_SQL, 0, 0 )... sColumn= sColumn || ‘, ‘ || ‘ PNr ’ = ‘ SNrID, Navn, PNr ‘ sInto= sInto || ‘ :dfnPNr ’ = ‘ :dfnSNrID, :dfsNavn, :dfnPNr ‘ sWhere= sWhere || ‘ PNr = ‘ || ‘ :dfnPNr ‘ = ‘ PNr = :dfnPNr ‘ = ‘ PNr = 6400 ‘

15 SQLHiA Dynamisk SQL-Bestem SELECT-statement sSelect SNrID Navn PNr 6400 Select frmSelger dfnSNrID dfsNavn dfnPNr pbSelect frmSelger Message Actions On PAM_SELECT... Call SalSendMsgToChildren ( hWndForm, PAM_SQL, 0, 0 ) Set sSelect = ‘SELECT ‘ || sColumn || ‘ INTO ‘ || sInto ‘ FROM ‘ || sFrom ‘ WHERE ‘ || sWhere... sColumn= sColumn || ‘, ‘ || ‘ PNr ’ = ‘ SNrID, Navn, PNr ‘ sInto= sInto || ‘ :dfnPNr ’ = ‘ :dfnSNrID, :dfsNavn, :dfnPNr ‘ sWhere= sWhere || ‘ PNr = ‘ || ‘ :dfnPNr ‘ = ‘ PNr = :dfnPNr ‘ = ‘ PNr = 6400 ‘ sSelect=SELECTSNrID, Navn, PNrINTO :dfnSNrID, :dfsNavn, :dfnPNr FROM Selger WHERE PNr = 6400

16 SQLHiA

17 SQLHiA Generering av dynamisk SQL-statement PAM_SELECT PAM_UPDATE... SQL Build PAM_SELECT PAM_UPDATE clsWnd Class Variables: sSql, sColumn, sInto, sTable, sWhere, sOrder,... Mdi Frm

18 SQLHiA

19 SQLHiA Klasser (1) clsSqlHandleStruct clsSqlDbAccess clsWnd clsWnd_Mdi clsWnd_TopLevel clsMdi clsFrm clsTbl clsWnd_ChildObject clsWnd_DfCmbMiCol clsDf clsDfRowID clsDfNum clsDfStr clsCmb clsCmbNum clsCmbStr clsCol clsCmbNum_AutoSelect clsCmbStr_AutoSelect clsColRowID clsColNum clsColStr clsMl

20 SQLHiA Klasser (2) clsPb clsPbMdiSelect clsPbMdiFirst clsPbMdiSelect clsPbMdiPrevious clsPbMdiNext clsPbMdiLast clsPbMdiUpdate clsPbMdiSave clsPbMdiInsert clsPbMdiDelete clsPbMdiNewRow clsPbMdiSort clsPbMdiHelp clsPbMdiPrint clsPbMdiClear

21 SQLHiA Klasse-notasjon ClassName Class Variables Instance Variables Functions Messages

22 SQLHiA

23 SQLHiA clsSqlHandleStruct iv_hSql bhSqlStatus iv_hSql bhSqlStatus clsSqlHandleStruct Instance Variable SqlHandle True if iv_hSql is connected

24 SQLHiA clsSqlDbAccess sSqlDatabase sSqlUser sSqlPassword cv_hSql[1:*] nConnected nMinHandles nMaxHandles sSqlStatement sSqlStatement_Select sSqlDatabase sSqlUser sSqlPassword cv_hSql[1:*] nConnected nMinHandles nMaxHandles sSqlStatement sSqlStatement_Select nResultSetCount nFetchRowNumber nResultSetCount nFetchRowNumber InitClass ConnectSqlHandles DisconnectAllSqlHandles SetSqlStatement SetIsolationLevel SetParameter Prepare Execute ExecuteSelect FetchRow FetchRow_Through First Previous Next Last Select Update Insert Delete RetrieveRow Error MessageBoxFetchError Select_Inst Update_Inst Insert_Inst Delete_Inst InitClass ConnectSqlHandles DisconnectAllSqlHandles SetSqlStatement SetIsolationLevel SetParameter Prepare Execute ExecuteSelect FetchRow FetchRow_Through First Previous Next Last Select Update Insert Delete RetrieveRow Error MessageBoxFetchError Select_Inst Update_Inst Insert_Inst Delete_Inst clsSqlDbAccess Initierer sSqlDatabase, sSqlUser, sSqlPassword Connect nMin SqlHandles Henter en rad på nytt etter UPDATE

25 SQLHiA clsWnd sMdiName sTopWndName sSql sColumn sInto sTable sWhere sOrder sOrderColumn sUpdateSet sInsertInto sInsertValue sDeleteValue sUpdates[1:*] hWndColSort bExists sTableArray[1:*] nTableArrayCont sFrom sConstraints sMdiName sTopWndName sSql sColumn sInto sTable sWhere sOrder sOrderColumn sUpdateSet sInsertInto sInsertValue sDeleteValue sUpdates[1:*] hWndColSort bExists sTableArray[1:*] nTableArrayCont sFrom sConstraints sItemName sDbTableName sDbColumnName sDbTableColumnName sItemName sDbTableName sDbColumnName sDbTableColumnName SetItemName SetDbTableName Set_TbName_ColName Set_TableArray Set_From_Constraints SetItemName SetDbTableName Set_TbName_ColName Set_TableArray Set_From_Constraints SAM_Create clsWnd Set the name of an object (frmMain, dfs_Adr_PNr) dfs_Adr_PNr --> Adr dfs_Adr_PNr --> PNr Set the Array-values of different Tables in a SqlStatement Set the FROM Clause and the Constraint part of a SELECT SqlStatement Call SetItemName( )

26 SQLHiA clsWnd_Mdi / clsWnd_TopLevel SAM_Create clsWnd_Mdi SetTopWndName Get_SqlHandle SQL_Build SQL_Select SQL_Insert SQL_Update SQL_Delete Clear Help_TopWindow SetTopWndName Get_SqlHandle SQL_Build SQL_Select SQL_Insert SQL_Update SQL_Delete Clear Help_TopWindow SAM_Create PAM_SELECT PAM_UPDATE PAM_INSERT PAM_DELETE PAM_CLEAR PAM_HELP SAM_Close SAM_Create PAM_SELECT PAM_UPDATE PAM_INSERT PAM_DELETE PAM_CLEAR PAM_HELP SAM_Close clsWnd_TopLevel

27 SQLHiA clsMdi / clsFrm / clsTbl hSqlDb clsMdi hSqlSelect hSqlUpdate hSqlInsert hSqlDelete hSql nFetch hSqlSelect hSqlUpdate hSqlInsert hSqlDelete hSql nFetch Set_SqlHandle Get_SqlHandle Select_Inst Update_Inst Insert_Inst Delete_Inst Clear Set_SqlHandle Get_SqlHandle Select_Inst Update_Inst Insert_Inst Delete_Inst Clear SAM_Create PAM_FIRST PAM_PREVIOUS PAM_NEXT PAM_LAST SAM_Create PAM_FIRST PAM_PREVIOUS PAM_NEXT PAM_LAST clsFrm hSqlTbl Get_SqlHandle Select_Inst Update_Inst Insert_Inst Delete_Inst SQL_SelectSort Clear Get_SqlHandle Select_Inst Update_Inst Insert_Inst Delete_Inst SQL_SelectSort Clear SAM_Create PAM_SORT PAM_NEWROW SAM_Create PAM_SORT PAM_NEWROW clsTbl

28 SQLHiA clsWnd_ChildObject / clsWnd_DfCmbMiCol sParentName clsWnd_ChildObject sItemValue Sql Sql_Select Sql_Update Sql_Insert Get_Equal Get_MyValue Sql Sql_Select Sql_Update Sql_Insert Get_Equal Get_MyValue SAM_Create PAM_SQL PAM_CLEAR SAM_Create PAM_SQL PAM_CLEAR clsWnd_DfCmbMiCol

29 SQLHiA clsDf sParentName Get_MyValue clsDf Sql Sql_Select Sql_Update Sql_Delete Sql Sql_Select Sql_Update Sql_Delete PAM_ROWID clsDfRowID sSelect Get_Equal clsDfNum sItemValue Get_Equal clsDfStr

30 SQLHiA clsCmb DropDown Click Get_MyValue DropDown Click Get_MyValue SAM_DropDown SAM_Click SAM_DropDown SAM_Click clsCmb Get_Equal clsCmbNum Get_Equal clsCmbStr DropDown Click DropDown Click SAM_Click clsCmbNum_AutoSelect DropDown Click DropDown Click SAM_Click clsCmbNum_AutoSelect

31 SQLHiA clsCol SAM_Click clsCol Sql Sql_Select Sql_Update Sql_Delete Sql Sql_Select Sql_Update Sql_Delete clsColRowID clsColNumclsColStr

32 SQLHiA clsMultiline SetDbColumnName clsMultiline

33 SQLHiA MdiWindow / FormWindow / TableWindow clsSqlDbAccess: hSqlDb clsSqlDbAccess clsWnd_TopLevel clsMdi clsWnd_Mdi clsFrm clsTbl

34 SQLHiA Bruk av virtuelle funksjons-kall f1 Call SalSendMsg(Obj1, Msg1…) On Msg1 Call..f1(…)

35 SQLHiA Navn-setting frmSelger cmb_Selger_SNrID ComboBoxTabell-NavnKolonne-navn dfs_Selger_RowIDSkjult RowID

36 SQLHiA UPDATE clsFrm Update Call Execute (hSqlUpdate) Call SqlSetParameter ( hSqlSelect, DBP_FETCHTHROUGH, TRUE, ‘‘) Call FetchRow_Through ( hSqlSelect, nFetchRowNumber, nInd) Call SqlSetParameter ( hSqlSelect, DBP_FETCHTHROUGH, FALSE, ‘‘) UPDATE Selger SET Navn = :cmb_Selger_Navn, PNr = :cmb_Selger_PNr WHERE ROWID = :dfs_Selger_RowID

37 SQLHiA End


Laste ned ppt "SQLHiA Kap 12 Dynamisk SQL. SQLHiA SQLHiA FlerbrukersystemClient / Server Database DBMS Application_2 SQL-Request Data Application_3 Application_1 ClientServer."

Liknende presentasjoner


Annonser fra Google