⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch23.htm

📁 VC使用所有细节的逻列
💻 HTM
📖 第 1 页 / 共 4 页
字号:
<H3>Working with Your Database</H3>

<P>The DataView gives you full control over not just the contents of your SQL database, but its design. A raft of graphical tools makes it easy to see how the database works, or to change any aspect of it.</P>

<P><B>Database Designer</B></P>

<P>Return to the DataView, right-click the <font color="#008000">authors</font> table, and choose Design. With the Database Designer, shown in Figure 23.21, you can change the key column, adjust the width, apply constraints on valid values and more.</P>

<A HREF="Xfigs21.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch23/Xfigs21.gif"><b>Fig. 23.21</b></A>

<P><I>The Database Designer lets you change any aspect of the design of your </I><I>database.</I></P>

<P>For example, click the Properties button at the rightmost end of the Table toolbar while au_id is selected to bring up the property sheet shown in Figure 23.22. The constraint shown here means that <font color="#008000">au_id</font> must be a 9 digit 
number. Clicking the Relationship tab, shown in Figure 23.23, shows that <font color="#008000">au_id</font> is used to connect the <font color="#008000">authors</font> table to the <font color="#008000">titleauthor</font> table.</P>

<A HREF="Xfigs22.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch23/Xfigs22.gif"><b>Fig. 23.22</b></A>

<P><I>It's simple to specify column constraints.</I></P>

<A HREF="Xfigs23.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch23/Xfigs23.gif"><b>Fig. 23.23</b></A>

<P><I>The Relationships tab makes it simple to see how tables are related.</I></P>

<P>If you're a database developer, you probably can't wait to open your own database in the Database Designer and set to work. Be sure to take advantage of the many shortcut menus available for you. For example, Figure 23.4 shows the menu that pops up 
when you right-click anywhere in the <font color="#008000">authors</font> grid. The first item, Column <U>P</U>roperties, is drawn with a pushed-in button to show it's selected. Select Column Na<U>m</U>es and the grid becomes much smaller&#151;bring back 
the shortcut menu and choose Column <U>P</U>roperties to return to the large grid of properties. Select <U>K</U>eys to see just those columns that are keys, and <U>N</U>ame Only to shrink the grid to a tiny column showing only the name of the table.</P>

<A HREF="Xfigs24.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch23/Xfigs24.gif"><b>Fig. 23.24</b></A>

<P><I>Shortcut menus make common tasks easy to select.</I></P>

<P><B>Database Diagrams</B></P>

<P>One of the easiest ways to get a lot of information across to people quickly is with a diagram. Figure 23.25 shows a diagram that explains the relationships between the three tables used throughout this chapter. To create the same diagram yourself, 
follow these steps:</P>

<ol> 

<li><P> Right-click Database Diagrams in DataView, and choose New Dia<U>g</U>ram.</P>

<li><P> Click authors and drag it into the working area.</P>

<li><P> Click titleauthor and drag it into the working area. Wait a moment for a link between authors and titleauthor to appear.</P>

<li><P> Click titles and drag it into the working area. Wait for the link to appear.</P>

<li><P> Rearrange the tables so that their keys are aligned as in Figure 23.25.</P>

<li><P> Drag the links up or down until they run from one key to another as they do in Figure 23.25.</P>

</ol>

<A HREF="Xfigs25.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch23/Xfigs25.gif"><b>Fig. 23.25</b></A>

<P><I>A picture is worth a thousand words when it's time to explain your </I><I>database design.</I></P>

<P>If you wish, you can save this diagram in the database. Just click the Save button on the Standard toolbar and provide a name. The diagrams will be available to any other developers who use the Enterprise Edition to access this database.</P>

<P>To change any design decision about these tables, bring up the shortcut menu and choose Column <U>P</U>roperties, then edit these properties just as you could in the Database Designer. How's that for an easy way to design and administer an SQL 
database?</P>

<H3>Understanding Microsoft Transaction Server</H3>

<P>Microsoft Transaction Server is a completely separate product that comes with the Enterprise Edition of Visual C++ but is not integrated with it. MTS enables you to use a collection of COM objects called components to securely implement distributed 
transactions within enterprise-scale database applications. Applications that use MTS can be written in any language that can produce ActiveX applications, including Visual C++, Visual J++, and Visual Basic.</P>

<P>To work with MTS, you must be comfortable doing under-the-hood ActiveX and COM programming, working directly with interfaces. If you've always relied on MFC to hide interfaces from you, you should probably read <A HREF="index21.htm" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/index21.htm" 
target="text">Chapter 21</A>, &quot;The Active Template Library,&quot; to gain an introduction to the way that interfaces are used. There's more information in the electronic copy of &#147;ActiveX Programming with Visual C++,&#148; which is included in its 
entirety on the CD that comes with this book</P>

<P>You can use MTS with almost any kind of database, including ordinary file systems, just as you can use ODBC with almost any kind of database. Certainly SQL databases will work with MTS, but so will a huge variety of other resource managers. This allows 
you access to the power of MTS without having to change your database system at all.</P>

<P>An MTS component is a COM object. It can do any specific task within your system, and often several components will be involved in a given <I>transaction</I>. Components are gathered together into packages which are installed as a unit onto your 
system.</P>

<P>A transaction is a unit of work that should succeed or fail as a whole. For example, if a customer is transferring money from one bank account to another, the money should be withdrawn from one account and deposited to the other. It does not make sense 
for one step in this process to fail and the other to proceed to completion. That would either take money away from customers unfairly, or give money to customers unfairly. Database programmers have long realized this, and developed ways of rolling back 
transactions that were partially completed when a step failed, or of pre-checking conditions to be sure that all the steps will succeed before starting. But these techniques are much more difficult to implement in a large, distributed system&#151;too 
difficult to implement by hand.</P>

<P>For example, imagine two systems are about to take money (say, $100) from a customer's bank account. The first checks the balance and there is enough money. Both systems are connected through a network to the system that keeps the balance for that 
account. The first system asks for the balance and gets the reply: $150. Moments later, the second asks and is also told $150. The first confidently sends the request for $100 and succeeds, the second asks just a fraction of a second later for $100 and 
fails. Any portions of a transaction involving this customer that were already completed by the second system will now have to be rolled back. A transactional system like MTS makes this process much simpler for developers by providing system services to 
support these tasks.</P>

<P>Sound good? Then install the product and get going in the online help. There are two good sample systems included: one is a simple banking application and the other is a game. You can also check out Microsoft's Transaction Server Web site at <A 
HREF="tppmsgs/msgs0.htm#30" tppabs="http://www.microsoft.com/transaction" target="_top"><B>http://www.microsoft.com/transaction</B></A>.</P>

<H3>Using Visual SourceSafe</H3>

<P>If you work as part of a team of developers, a revision control system isn't just a nicety, it's a necessity. For too many teams the revision control system consists of sticking your head into the hall and telling your fellow programmers that you'll be 
working on fooble.h and fooble.cpp for a while, and to leave them alone. Or perhaps it is more about demanding to know who saved their changes to fooble.h over your changes because you both had the file open at once, and somebody saved after you did. There 
is a better way.</P>

<P>Revision control systems are not a new idea. They all implement these concepts:</P>

<ul>

<li> <B>Check out a file</B>&#151;by bringing a copy of a file down to your desktop from a central library or repository, you mark the file as unavailable to others who might want to change it. (Some systems allow changes by several developers at once to 
source files and can merge them later.)</P>

<li> <B>Check in a file</B>&#151;when your changes are complete, you return the file to the library. You provide a brief description of what you've done, and the RCS adds your name, the date, and other files affected by this change automatically.</P>

<li> <B>Merge changes</B>&#151;some RCS systems can accept check-ins by different developers on the same file, and will make sure that both sets of changes appear in the central file.</P>

<li> <B>Change tracking</B>&#151;some RCS systems can reconstruct earlier versions of a file by working backwards through a change log</P>

<li> <B>History</B>&#151;the information added at check-in can form a nice summary of what was done to each file, when and why.</P>

</ul>

<P>Microsoft's Visual Source Safe is a good revision control system that many developers use to keep their code in order. What sets Visual SourceSafe apart from other RCS systems? It's project-oriented, it hooks into Visual C++ (through the new SCCI 
interface, some other RCS systems can also hook in,) and it comes with the Enterprise Edition of Visual C++.</P>

<P>When you install Visual SourceSafe, choose a custom installation and select Enable SourceSafe Integration. Doing this adds a cascading menu to Developer Studio's Project menu, shown in Figure 23.26.</P>

<A HREF="Xfigs26.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch23/Xfigs26.gif"><b>Fig. 23.26</b></A>

<P><I>Installing Visual SourceSafe adds a cascading menu to the Project menu.</I></P>

<P>The items on the menu are as follows:</P>

<ul>

<li> <B><U>G</U></B><B>et Latest Version</B>&#151;For selected files, replace your copies with newer copies from the library.</P>

<li> <B>Check </B><B><U>O</U></B><B>ut</B>&#151;Start to work on a file</P>

<li> <B>Check </B><B><U>I</U></B><B>n</B>&#151;Finish working on a file and make your changed versions available to everyone</P>

<li> <B><U>U</U></B><B>ndo Check Out</B>&#151;Give back a file without making any changes or an entry in the history</P>

<li> <B><U>A</U></B><B>dd To Source Control</B>&#151;Enable source control for this project</P>

<li> <B>Re</B><B><U>m</U></B><B>ove From Source Control</B>&#151;Disable source control for this project</P>

<li> <B>Show </B><B><U>H</U></B><B>istory</B>&#151;Display the changes made to selected files</P>

<li> <B>Show </B><B><U>D</U></B><B>ifferences</B>&#151;Display the differences between old and new files</P>

<li> <B>SourceSafe </B><B><U>P</U></B><B>roperties</B>&#151;See information SourceSafe keeps about your files</P>

<li> <B>Shar</B><B><U>e</U></B><B> From SourceSafe</B>&#151;Allow other developers to work on selected files</P>

<li> <B><U>R</U></B><B>efresh Status</B>&#151;Update your display with status changes made by other developers</P>

<li> <B>Source Safe</B>&#151;Run Visual SourceSafe to see reports and summaries</P>

</ul>

<P>You must have an account and password set up in Visual SourceSafe before you can put a project under source control and use these features. Run Visual SourceSafe from this menu to perform any administrative tasks that have not already been taken care 
of for you.</P>

<P>Unless you are the only developer who will work on your project, you simply must use a revision control system. Visual SourceSafe is good, it works from within Developer Studio, and if you have the Enterprise Edition of Visual C++, it's free. What more 
could you want? Install it, learn it, use it. You won't regret it.</P>

<blockquote><p><img src="tip.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/tip.gif">

<P>Revision control systems work as well on Web pages, database contents, documentation, bug lists, and spreadsheets as they do on code and program files. Once you get the habit and see the benefits, you just won't stop.</P>

<p><img src="bottom.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/bottom.gif"></blockquote>

<H3>From Here...</H3>

<P>This chapter has introduced you to the Enterprise Edition of Visual C++. You've seen how easy it is to integrate C++ and SQL programming, even if your SQL is weak. The sample application in this chapter calls a simple stored procedure, and you can use 
this technique to call stored procedures written by SQL developers and wrap them in a friendly interface. You've also briefly met the Microsoft Transaction Server and Visual SourceSafe, two stand-alone products that come with the Enterprise Edition.</P>

<P>For information on related topics, try these chapters:</P>

<ul>

<li> <A HREF="index02.htm" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/index02.htm" target="text">Chapter 2</A>, &quot;Dialog Boxes and Controls,&quot; introduces the steps involved in adding controls to a dialog.</P>

<li> <A HREF="index22.htm" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/index22.htm" target="text">Chapter 22</A>, &quot;Database Access,&quot; covers the fundamentals of record sets, record views, and ODBC.</P>

<li> <A HREF="index21.htm" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/index21.htm" target="text">Chapter 21</A>, &quot;The Active Template Library,&quot; pulls back the MFC covers to reveal the COM interfaces that power ActiveX.</P>

<li> <A HREF="index25.htm" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/index25.htm" target="text">Chapter 25</A>, &quot;Achieving Reuse with the Gallery and Your Own AppWizards,&quot; discusses some other ways that developers can share their work to produce amazing applications more quickly than ever 
before.</P>

</ul>

<p><hr></p>

<center>

<p><font size=-2>

&copy; 1997, QUE Corporation, an imprint of Macmillan Publishing USA, a

Simon and Schuster Company.</font></p>

</center>

</BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -