• What Do You Need Help With? V8
    1,074 replies, posted
[QUOTE=mib999;52810102]Visual Studio does this automatically if it means something.[/QUOTE] yeah, and its one of the things i miss about it. i use vs code on ubuntu mainly at work, since it's a bit easier in many ways and is certainly easier when i need to consider building for mac osx too
[QUOTE=paindoc;52810115]yeah, and its one of the things i miss about it. i use vs code on ubuntu mainly at work, since it's a bit easier in many ways and is certainly easier when i need to consider building for mac osx too[/QUOTE] :(, Gotta love VS Code though, much easier to handle.
[QUOTE=mib999;52810362]:(, Gotta love VS Code though, much easier to handle.[/QUOTE] that and it picks up links from the terminal when i run clang-tidy, so i can ctrl-click to go where a problem is
So I'm doing something for a class using ASP.NET, SQL and VB, and I've ran into an [url="https://i.imgur.com/NPlLdyC.png"]error[/url] that I cannot figure the cause of. I've checked through and everything looks correct, and this only happened once I added the publishers via copying and changing the code for the authors. Here is the [url="https://imgur.com/SdFRiNx.png"]authors table[/url] and the [url="https://imgur.com/T2vWDk0.png"]publishers table.[/url] And yes, the primary keys are the IDs. ASP.NET: [code] <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %> <!DOCTYPE html> <html> <head id="Head1" runat="server"> <title>Manage Data</title> </head> <body> <form id="form1" runat="server"> <table bgcolor="gray"> <%--Authors--%> <tr> <td valign="top"> <asp:GridView ID="GridView1" AllowSorting="True" AllowPaging="True" runat="server" DataSourceID="SqlDataSource2" DataKeyNames="authorID" AutoGenerateColumns="False" Width="500px" SelectedIndex="0" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnPageIndexChanged="GridView1_PageIndexChanged" OnRowDeleted="GridView1_RowDeleted" OnSorted="GridView1_Sorted" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Vertical"> <AlternatingRowStyle BackColor="White" /> <Columns> <asp:CommandField ShowSelectButton="true" ShowDeleteButton="true" /> <asp:BoundField DataField="authorID" HeaderText="ID" ReadOnly="True" SortExpression="authorID" /> <asp:BoundField DataField="authorName" HeaderText="Name" SortExpression="authorName" /> </Columns> <FooterStyle BackColor="#CCCC99" /> <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" /> <RowStyle BackColor="#F7F7DE" /> <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" /> <SortedAscendingCellStyle BackColor="#FBFBF2" /> <SortedAscendingHeaderStyle BackColor="#848384" /> <SortedDescendingCellStyle BackColor="#EAEAD3" /> <SortedDescendingHeaderStyle BackColor="#575357" /> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource2" runat="server" SelectCommand = "SELECT authorID, authorName FROM authors" DeleteCommand = "DELETE FROM authors WHERE authorID = @authorID" ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>" ProviderName="<%$ ConnectionStrings:ConnectionString2.ProviderName %>" > </asp:SqlDataSource> </td> <td valign="top"> <asp:DetailsView AutoGenerateRows="False" DataKeyNames="authorID" DataSourceID="SqlDataSource3" HeaderText="Author Details" ID="DetailsView1" runat="server" Width="275px" OnItemUpdated="DetailsView1_ItemUpdated" OnItemInserted="DetailsView1_ItemInserted" OnDataBound="DetailsView1_DataBound" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Vertical" > <AlternatingRowStyle BackColor="White" /> <EditRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" /> <Fields> <asp:BoundField DataField="authorID" HeaderText="ID" ReadOnly="true" SortExpression="authorID" InsertVisible="False" /> <asp:BoundField DataField="authorName" HeaderText="Name" SortExpression="authorName" /> <asp:BoundField DataField="email" HeaderText="Email" SortExpression="email" /> <asp:BoundField DataField="sex" HeaderText="Sex" SortExpression="sex" /> </Fields> <FooterStyle BackColor="#CCCCCC" /> <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" /> <RowStyle BackColor="#F7F7DE" /> </asp:DetailsView> <br /> <br /> <asp:SqlDataSource ID="SqlDataSource3" runat="server" SelectCommand = "SELECT authorID, authorName, email, sex FROM authors WHERE authorID = @authorID" UpdateCommand = "UPDATE authors SET authorName = @authorName, email = @email, sex = @sex WHERE authorID = @authorID" InsertCommand = "INSERT INTO authors ( authorID, authorName, email, sex) VALUES( @authorID, @authorName, @email, @sex)" ConnectionString="<%$ ConnectionStrings:ConnectionString3 %>" ProviderName="<%$ ConnectionStrings:ConnectionString3.ProviderName %>" > <UpdateParameters> <asp:Parameter Name="authorName" Type="String" /> <asp:Parameter Name="email" Type="String" /> <asp:Parameter Name="sex" Type="String" /> <asp:Parameter Name="authorID" Type="String" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="authorID" Type="String" /> <asp:Parameter Name="authorName" Type="String" /> <asp:Parameter Name="email" Type="String" /> <asp:Parameter Name="sex" Type="String" /> </InsertParameters> </asp:SqlDataSource> </td> </tr> <%--Publishers--%> <tr> <td valign="top"> <asp:GridView ID="GridView2" AllowSorting="True" AllowPaging="True" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="pubID" AutoGenerateColumns="False" Width="500px" SelectedIndex="0" OnSelectedIndexChanged="GridView2_SelectedIndexChanged" OnPageIndexChanged="GridView2_PageIndexChanged" OnRowDeleted="GridView2_RowDeleted" OnSorted="GridView2_Sorted" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Vertical"> <AlternatingRowStyle BackColor="White" /> <Columns> <asp:CommandField ShowSelectButton="true" ShowDeleteButton="true" /> <asp:BoundField DataField="pubID" HeaderText="PID" ReadOnly="True" SortExpression="pubID" /> <asp:BoundField DataField="pubName" HeaderText="Name" SortExpression="pubName" /> </Columns> <FooterStyle BackColor="#CCCC99" /> <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" /> <RowStyle BackColor="#F7F7DE" /> <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" /> <SortedAscendingCellStyle BackColor="#FBFBF2" /> <SortedAscendingHeaderStyle BackColor="#848384" /> <SortedDescendingCellStyle BackColor="#EAEAD3" /> <SortedDescendingHeaderStyle BackColor="#575357" /> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" SelectCommand = "SELECT pubID, pubName FROM publishers" DeleteCommand = "DELETE FROM publishers WHERE pubID = @pubID" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" > </asp:SqlDataSource> </td> <td valign="top"> <asp:DetailsView AutoGenerateRows="False" DataKeyNames="pubID" DataSourceID="SqlDataSource4" HeaderText="Publisher Details" ID="DetailsView2" runat="server" Width="275px" OnItemUpdated="DetailsView2_ItemUpdated" OnItemInserted="DetailsView2_ItemInserted" OnDataBound="DetailsView2_DataBound" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Vertical" > <AlternatingRowStyle BackColor="White" /> <EditRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" /> <Fields> <asp:BoundField DataField="pubID" HeaderText="PID" ReadOnly="true" SortExpression="pubID" InsertVisible="False" /> <asp:BoundField DataField="pubName" HeaderText="Name" SortExpression="pubName" /> <asp:BoundField DataField="pubCity" HeaderText="City" SortExpression="pubCity" /> </Fields> <FooterStyle BackColor="#CCCCCC" /> <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" /> <RowStyle BackColor="#F7F7DE" /> </asp:DetailsView> <br /> <br /> <asp:SqlDataSource ID="SqlDataSource4" runat="server" SelectCommand = "SELECT pubID, pubName, pubCity FROM publishers WHERE pubID = @pubID" UpdateCommand = "UPDATE publishers SET pubName = @pubName, pubCity = @pubCity WHERE pubID = @pubID" InsertCommand = "INSERT INTO publishers ( pubID, pubName, pubCity) VALUES( @pubID, @pubName, @pubCity)" ConnectionString="<%$ ConnectionStrings:ConnectionString4 %>" ProviderName="<%$ ConnectionStrings:ConnectionString4.ProviderName %>" > <UpdateParameters> <asp:Parameter Name="pubName" Type="String" /> <asp:Parameter Name="pubCity" Type="String" /> <asp:Parameter Name="pubID" Type="String" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="pubID" Type="String" /> <asp:Parameter Name="pubName" Type="String" /> <asp:Parameter Name="pubCity" Type="String" /> </InsertParameters> </asp:SqlDataSource> </td> </tr> </table> <asp:Label ID="ErrorMessageLabel" EnableViewState="false" runat="server" /> </form> </body> </html> [/code] VB: [code] Partial Class _Default Inherits System.Web.UI.Page Protected Sub DetailsView1_ItemInserted( ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertedEventArgs) If (Not e.Exception Is Nothing) Then ErrorMessageLabel.Text = "An error occured while entering this record. " ErrorMessageLabel.Text += "Please verify you have entered data in the correct format." e.ExceptionHandled = True End If GridView1.DataBind() End Sub Protected Sub DetailsView1_ItemUpdated( ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdatedEventArgs) GridView1.DataBind() End Sub Protected Sub DropDownList1_SelectedIndexChanged( ByVal sender As Object, ByVal e As EventArgs) DetailsView1.ChangeMode(DetailsViewMode.ReadOnly) End Sub Protected Sub GridView1_SelectedIndexChanged( ByVal sender As Object, ByVal e As EventArgs) DetailsView1.ChangeMode(DetailsViewMode.ReadOnly) End Sub Protected Sub GridView1_PageIndexChanged( ByVal sender As Object, ByVal e As EventArgs) DetailsView1.ChangeMode(DetailsViewMode.ReadOnly) End Sub Protected Sub GridView1_Sorted( ByVal sender As Object, ByVal e As System.EventArgs) DetailsView1.ChangeMode(DetailsViewMode.ReadOnly) End Sub Protected Sub GridView1_RowDeleted( ByVal sender As Object, ByVal e As GridViewDeletedEventArgs) If (Not e.Exception Is Nothing) Then ErrorMessageLabel.Text = "Failed to DELETE due to foreign key contstraint. " ErrorMessageLabel.Text += "You may only delete rows which have no related records." e.ExceptionHandled = True End If End Sub Protected Sub DetailsView1_DataBound( ByVal sender As Object, ByVal e As EventArgs) If (DetailsView1.CurrentMode = DetailsViewMode.Insert) Then Dim stateTextBox As TextBox = CType( DetailsView1.Rows(3).Cells(1).Controls(0), TextBox) End If End Sub Protected Sub DetailsView2_ItemInserted( ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertedEventArgs) If (Not e.Exception Is Nothing) Then ErrorMessageLabel.Text = "An error occured while entering this record. " ErrorMessageLabel.Text += "Please verify you have entered data in the correct format." e.ExceptionHandled = True End If GridView2.DataBind() End Sub Protected Sub DetailsView2_ItemUpdated( ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdatedEventArgs) GridView2.DataBind() End Sub Protected Sub DropDownList2_SelectedIndexChanged( ByVal sender As Object, ByVal e As EventArgs) DetailsView2.ChangeMode(DetailsViewMode.ReadOnly) End Sub Protected Sub GridView2_SelectedIndexChanged( ByVal sender As Object, ByVal e As EventArgs) DetailsView2.ChangeMode(DetailsViewMode.ReadOnly) End Sub Protected Sub GridView2_PageIndexChanged( ByVal sender As Object, ByVal e As EventArgs) DetailsView2.ChangeMode(DetailsViewMode.ReadOnly) End Sub Protected Sub GridView2_Sorted( ByVal sender As Object, ByVal e As System.EventArgs) DetailsView2.ChangeMode(DetailsViewMode.ReadOnly) End Sub Protected Sub GridView2_RowDeleted( ByVal sender As Object, ByVal e As GridViewDeletedEventArgs) If (Not e.Exception Is Nothing) Then ErrorMessageLabel.Text = "Failed to DELETE due to foreign key contstraint. " ErrorMessageLabel.Text += "You may only delete rows which have no related records." e.ExceptionHandled = True End If End Sub Protected Sub DetailsView2_DataBound( ByVal sender As Object, ByVal e As EventArgs) If (DetailsView2.CurrentMode = DetailsViewMode.Insert) Then Dim stateTextBox As TextBox = CType( DetailsView2.Rows(2).Cells(1).Controls(0), TextBox) End If End Sub End Class [/code] Any ideas?
You are executing some SQL without filling in those parameters that start with "@" in query definition.
[QUOTE=DroppingPOCD;52817042]You are executing some SQL without filling in those parameters that start with "@" in query definition.[/QUOTE] Am I blind? Where exactly?
[QUOTE=Frosty701;52817153]Am I blind? Where exactly?[/QUOTE] I don't know mate, I can't even see where you bind anything to those parameters at all.
[QUOTE=DroppingPOCD;52817189]I don't know mate, I can't even see where you bind anything to those parameters at all.[/QUOTE] Isn't that literally what this is? [code] <UpdateParameters> <asp:Parameter Name="authorName" Type="String" /> <asp:Parameter Name="email" Type="String" /> <asp:Parameter Name="sex" Type="String" /> <asp:Parameter Name="authorID" Type="String" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="authorID" Type="String" /> <asp:Parameter Name="authorName" Type="String" /> <asp:Parameter Name="email" Type="String" /> <asp:Parameter Name="sex" Type="String" /> </InsertParameters> ~~~~ <UpdateParameters> <asp:Parameter Name="pubName" Type="String" /> <asp:Parameter Name="pubCity" Type="String" /> <asp:Parameter Name="pubID" Type="String" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="pubID" Type="String" /> <asp:Parameter Name="pubName" Type="String" /> <asp:Parameter Name="pubCity" Type="String" /> </InsertParameters> [/code]
[QUOTE=Frosty701;52817243]Isn't that literally what this is? [code] <UpdateParameters> <asp:Parameter Name="authorName" Type="String" /> <asp:Parameter Name="email" Type="String" /> <asp:Parameter Name="sex" Type="String" /> <asp:Parameter Name="authorID" Type="String" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="authorID" Type="String" /> <asp:Parameter Name="authorName" Type="String" /> <asp:Parameter Name="email" Type="String" /> <asp:Parameter Name="sex" Type="String" /> </InsertParameters> ~~~~ <UpdateParameters> <asp:Parameter Name="pubName" Type="String" /> <asp:Parameter Name="pubCity" Type="String" /> <asp:Parameter Name="pubID" Type="String" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="pubID" Type="String" /> <asp:Parameter Name="pubName" Type="String" /> <asp:Parameter Name="pubCity" Type="String" /> </InsertParameters> [/code][/QUOTE] No, you need to bind actual data to the query before you execute it.
[QUOTE=DroppingPOCD;52817271]No, you need to bind actual data to the query before you execute it.[/QUOTE] Oh I did. The SqlDataSource's are binded to a database, which is why I'm not understanding why it isn't working.
[QUOTE=Frosty701;52817274]Oh I did. The SqlDataSource's are binded to a database, which is why I'm not understanding why it isn't working.[/QUOTE] No, parameters are kinda like placeholders in your SQL query that you have to fill with some argument data before you execute said queries.
[QUOTE=DroppingPOCD;52817298]No, parameters are kinda like placeholders in your SQL query that you have to fill with some argument data before you execute said queries.[/QUOTE] I'm aware of that, but I just don't understand the point you're trying to make. I have multiple SQL statements and the author SQL statements worked literally just fine before I added the publishers which are copies of the author SQL statements just with changed data. [editline]d[/editline] Well I figured it out, and he was right I guess. For some reason VS decided it would be funny to delete the SelectParameters when I was copying things. Thanks Microsoft.
C++ QUESTION: If I have four colors of type Color and they're never going to change, and I'm going to be using it for a void function, what's the best way to store those four colors and reference them for later use? The Color structure is created by Color(0-255, 0-255, 0-255) for RGB.
Depends when and how you plan on using them kind of. Could be better as static constant member functions or constant global variables (header or source depending on the scope they are needed).
I'm basically making a printing function that takes a message and a color as parameters. The color is going to represent errors, successes, and general logging into for my Garry's Mod module.
Hm well do you need to use the colors outside of the function? If not then are your colors predefined? If so pass by const ref and make the colors themselves constant. If not, well I'd still pass by const at least and by reference if the colors exist outside of the function (ie predefined or created at call time)
hey so i'm using WAMP and phpmyadmin to try and upload a SQL database, but whenever i import the schema file i get a bunch of syntax errors, it even says my comments aren't using the correct syntax [code]Static analysis: 7 errors were found during analysis. Unexpected beginning of statement. (near "Muhammad" at position 2) Unexpected beginning of statement. (near "Abed" at position 11) Unexpected beginning of statement. (near "Homework" at position 19) Unexpected beginning of statement. (near "5" at position 28) Unexpected beginning of statement. (near "CSCI" at position 33) Unexpected beginning of statement. (near "4560" at position 38) Unrecognized statement type. (near "Schema" at position 46) SQL query: --Muhammad Abed --Homework 5 --CSCI 4560 --Schema file for the database --create table Supplier Create table SUPPLIER( Sno char(2), Sname varchar(15) NOT NULL, "Status" int, City varchar(15), check("Status" >= 0), Primary Key(Sno) ) MySQL said: Documentation #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '--Muhammad Abed --Homework 5 --CSCI 4560 --Schema file for the database --' at line 1[/code] that's the error it's giving me and this is the SQL file: [code]--Muhammad Abed --Homework 5 --CSCI 4560 --Schema file for the database --create table Supplier Create table SUPPLIER( Sno char(2), Sname varchar(15) NOT NULL, "Status" int, City varchar(15), check("Status" >= 0), Primary Key(Sno) ); --create table Part Create table PART( Pno char(2), Pname varchar(15) NOT NULL, Color varchar(15), "Weight" INT, City varchar(15), check("Weight" >=1 AND "Weight" <= 100), UNIQUE(Pname, Color), Primary Key(Pno) ); --create table shipment Create table SHIPMENT( Sno char(2), Pno char(2), Qty int DEFAULT 100, Price float, check(Price >=0), Primary Key(Sno, Pno), Foreign Key(Sno) References SUPPLIER(Sno), Foreign Key(Pno) References PART(Pno) ); --SUPPLIER INSERT INSERT INTO SUPPLIER (Sno, Sname, Status, City ) VALUES ('s1', 'Smith', 20, 'London'); INSERT INTO SUPPLIER (Sno, Sname, Status, City ) VALUES ('s2', 'Jones', 10, 'Paris'); INSERT INTO SUPPLIER (Sno, Sname, Status, City ) VALUES ('s3', 'Blake', 30, 'Paris'); INSERT INTO SUPPLIER (Sno, Sname, Status, City ) VALUES ('s4', 'Clark', 20, 'London'); INSERT INTO SUPPLIER (Sno, Sname, Status, City ) VALUES ('s5', 'Adams', 30, NULL); -- PART INSERT INSERT INTO PART (Pno, Pname, Color, Weight, City) VALUES ('p1', 'Nut', 'Red', 12, 'London'); INSERT INTO PART (Pno, Pname, Color, Weight, City) VALUES ('p2', 'Bolt', 'Green', 17, 'Paris'); INSERT INTO PART (Pno, Pname, Color, Weight, City) VALUES ('p3', 'Screw', NULL, 17, 'Rome'); INSERT INTO PART (Pno, Pname, Color, Weight, City) VALUES ('p4', 'Screw', 'Red', 14, 'London'); INSERT INTO PART (Pno, Pname, Color, Weight, City) VALUES ('p5', 'cam', 'Blue', 12, 'Paris'); INSERT INTO PART (Pno, Pname, Color, Weight, City) VALUES ('p6', 'cog', 'Red', 19, 'London'); --SHIPMENT INSERT INSERT INTO SHIPMENT (Sno, Pno, Qty, Price) VALUES ('s1','p1', 300 ,.005); INSERT INTO SHIPMENT (Sno, Pno, Qty, Price) VALUES ('s1', 'p2', 200, .009); INSERT INTO SHIPMENT (Sno, Pno, Qty, Price) VALUES ('s1', 'p3', 400, .004); INSERT INTO SHIPMENT (Sno, Pno, Qty, Price) VALUES ('s1', 'p4', 200, .009); INSERT INTO SHIPMENT (Sno, Pno, Qty, Price) VALUES ('s1', 'p5', 100, .01); INSERT INTO SHIPMENT (Sno, Pno, Qty, Price) VALUES ('s1', 'p6', 100, .01); INSERT INTO SHIPMENT (Sno, Pno, Qty, Price) VALUES ('s2', 'p1', 300, .006); INSERT INTO SHIPMENT (Sno, Pno, Qty, Price) VALUES ('s2', 'p2', 400, .004); INSERT INTO SHIPMENT (Sno, Pno, Qty, Price) VALUES ('s3', 'p2', 200, .009); INSERT INTO SHIPMENT (Sno, Pno, Qty, Price) VALUES ('s3', 'p3', 200, NULL); INSERT INTO SHIPMENT (Sno, Pno, Qty, Price) VALUES ('s4', 'p2', 200, .008); INSERT INTO SHIPMENT (Sno, Pno, Qty, Price) VALUES ('s4', 'p3', NULL, NULL); INSERT INTO SHIPMENT (Sno, Pno, Qty, Price) VALUES ('s4', 'p4', 300, .006); INSERT INTO SHIPMENT (Sno, Pno, Qty, Price) VALUES ('s4', 'p5', 400, .003); [/code] i'm new to this so i'm not sure what i'm missing or what would cause this to happen, but my syntax seems fine?
[QUOTE=wauterboi;52818767]I'm basically making a printing function that takes a message and a color as parameters. The color is going to represent errors, successes, and general logging into for my Garry's Mod module.[/QUOTE] If you have several never-changing instances of your Color object, do the following: [cpp] struct Color { constexpr Color(const uint8_t& _r, const uint8_t& _g, const uint8_t& _b) : r(_r), g(_g), b(_b) {} uint8_t r, g, b; }; constexpr static Color RED(255, 0, 0); constexpr static Color BLUE(0, 0, 255); // ... etc [/cpp] constexpr denotes compile-time constants, and by declaring the Color constructor constexpr you can make compile-time constant color objects. Then you can freely reference these in your function. you can also declare them as constexpr in the scope of the function alone, since i imagine names like "RED" are somewhat common and you want to avoid potential naming conflicts: [cpp] void do_thing() { constexpr static Color RED(255, 0, 0); // ... do the thing } [/cpp] constexpr is the ideal way (if such a thing exists for global vars) of doing global variables from C++11 forward. Otherwise, if you can't make constexpr work, just declare them as static const in the scope of the function. Any of the ways mentioned will make it so you don't have to pass them as variables.
[QUOTE=JerryK;52820199]hey so i'm using WAMP and phpmyadmin to try and upload a SQL database, but whenever i import the schema file i get a bunch of syntax errors, it even says my comments aren't using the correct syntax [code]Static analysis: 7 errors were found during analysis. Unexpected beginning of statement. (near "Muhammad" at position 2) Unexpected beginning of statement. (near "Abed" at position 11) Unexpected beginning of statement. (near "Homework" at position 19) Unexpected beginning of statement. (near "5" at position 28) Unexpected beginning of statement. (near "CSCI" at position 33) Unexpected beginning of statement. (near "4560" at position 38) Unrecognized statement type. (near "Schema" at position 46) SQL query: --Muhammad Abed --Homework 5 --CSCI 4560 --Schema file for the database --create table Supplier Create table SUPPLIER( Sno char(2), Sname varchar(15) NOT NULL, "Status" int, City varchar(15), check("Status" >= 0), Primary Key(Sno) ) MySQL said: Documentation #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '--Muhammad Abed --Homework 5 --CSCI 4560 --Schema file for the database --' at line 1[/code] that's the error it's giving me and this is the SQL file: [code]--Muhammad Abed --Homework 5 --CSCI 4560 --Schema file for the database --create table Supplier Create table SUPPLIER( Sno char(2), Sname varchar(15) NOT NULL, "Status" int, City varchar(15), check("Status" >= 0), Primary Key(Sno) ); --create table Part Create table PART( Pno char(2), Pname varchar(15) NOT NULL, Color varchar(15), "Weight" INT, City varchar(15), check("Weight" >=1 AND "Weight" <= 100), UNIQUE(Pname, Color), Primary Key(Pno) ); --create table shipment Create table SHIPMENT( Sno char(2), Pno char(2), Qty int DEFAULT 100, Price float, check(Price >=0), Primary Key(Sno, Pno), Foreign Key(Sno) References SUPPLIER(Sno), Foreign Key(Pno) References PART(Pno) ); --SUPPLIER INSERT INSERT INTO SUPPLIER (Sno, Sname, Status, City ) VALUES ('s1', 'Smith', 20, 'London'); INSERT INTO SUPPLIER (Sno, Sname, Status, City ) VALUES ('s2', 'Jones', 10, 'Paris'); INSERT INTO SUPPLIER (Sno, Sname, Status, City ) VALUES ('s3', 'Blake', 30, 'Paris'); INSERT INTO SUPPLIER (Sno, Sname, Status, City ) VALUES ('s4', 'Clark', 20, 'London'); INSERT INTO SUPPLIER (Sno, Sname, Status, City ) VALUES ('s5', 'Adams', 30, NULL); -- PART INSERT INSERT INTO PART (Pno, Pname, Color, Weight, City) VALUES ('p1', 'Nut', 'Red', 12, 'London'); INSERT INTO PART (Pno, Pname, Color, Weight, City) VALUES ('p2', 'Bolt', 'Green', 17, 'Paris'); INSERT INTO PART (Pno, Pname, Color, Weight, City) VALUES ('p3', 'Screw', NULL, 17, 'Rome'); INSERT INTO PART (Pno, Pname, Color, Weight, City) VALUES ('p4', 'Screw', 'Red', 14, 'London'); INSERT INTO PART (Pno, Pname, Color, Weight, City) VALUES ('p5', 'cam', 'Blue', 12, 'Paris'); INSERT INTO PART (Pno, Pname, Color, Weight, City) VALUES ('p6', 'cog', 'Red', 19, 'London'); --SHIPMENT INSERT INSERT INTO SHIPMENT (Sno, Pno, Qty, Price) VALUES ('s1','p1', 300 ,.005); INSERT INTO SHIPMENT (Sno, Pno, Qty, Price) VALUES ('s1', 'p2', 200, .009); INSERT INTO SHIPMENT (Sno, Pno, Qty, Price) VALUES ('s1', 'p3', 400, .004); INSERT INTO SHIPMENT (Sno, Pno, Qty, Price) VALUES ('s1', 'p4', 200, .009); INSERT INTO SHIPMENT (Sno, Pno, Qty, Price) VALUES ('s1', 'p5', 100, .01); INSERT INTO SHIPMENT (Sno, Pno, Qty, Price) VALUES ('s1', 'p6', 100, .01); INSERT INTO SHIPMENT (Sno, Pno, Qty, Price) VALUES ('s2', 'p1', 300, .006); INSERT INTO SHIPMENT (Sno, Pno, Qty, Price) VALUES ('s2', 'p2', 400, .004); INSERT INTO SHIPMENT (Sno, Pno, Qty, Price) VALUES ('s3', 'p2', 200, .009); INSERT INTO SHIPMENT (Sno, Pno, Qty, Price) VALUES ('s3', 'p3', 200, NULL); INSERT INTO SHIPMENT (Sno, Pno, Qty, Price) VALUES ('s4', 'p2', 200, .008); INSERT INTO SHIPMENT (Sno, Pno, Qty, Price) VALUES ('s4', 'p3', NULL, NULL); INSERT INTO SHIPMENT (Sno, Pno, Qty, Price) VALUES ('s4', 'p4', 300, .006); INSERT INTO SHIPMENT (Sno, Pno, Qty, Price) VALUES ('s4', 'p5', 400, .003); [/code] i'm new to this so i'm not sure what i'm missing or what would cause this to happen, but my syntax seems fine?[/QUOTE] It's hard to read when you have so many line breaks (I wonder if that could be the problem). But in order to solve this, I would remove most of your SQL statements and make sure they work one by one. Start by making sure the CREATE TABLE statements work as intended then keep going down the list.
Having some issues with how to structure NodeJS applications. I am currently working on a Battery Monitor for some Solar Panels. I haven't got the measurement going but I know the whole thing will be packed into some Raspberry Pi. I have a simple Express Server working now with some metrics. But I was then thinking that I wanted to add all the sensory data into a database so I could see graphs over time. Now would I have both the sensoring, the database handling and the express server in the same application? Would it make sense to spread over multiple files? I am still super unsure how NodeJS works exactly in that regards as I can't fully gasp how functions get called. It makes sense for me to have some kind of main function which then have a update function for each thing that I described, but I am just puzzled on how that works together with. Ex. the functions that I use to start the Express server. I would love if any of you had some examples of likely programs with simple implementations that just shows the concept of how it should (or can be) done. I am generally really experience with C#/Java and getting into C++ at University. But for some reason NodeJS kicks me in the head in how you structure your program.
[QUOTE=brianosaur;52820564]It's hard to read when you have so many line breaks (I wonder if that could be the problem). But in order to solve this, I would remove most of your SQL statements and make sure they work one by one. Start by making sure the CREATE TABLE statements work as intended then keep going down the list.[/QUOTE] took a couple hours but i found all the issues, everything from quotations to no spaces after -- lol
Is it bad practice when writing your own libraries to split declarations and definitions between adjacent libraries? I'm trying to write a plugin system where I have a core library with some really generic objects, and other plugin libraries that link against core and provide the missing definitions. Sure I could just move the declarations into the plugin library, but it would be redundant and duplicate code because each plugin of that category would have the same declarations, just different definitions.
[QUOTE=wauterboi;52818767]I'm basically making a printing function that takes a message and a color as parameters. The color is going to represent errors, successes, and general logging into for my Garry's Mod module.[/QUOTE] My take on this: [cpp] struct Color { int r, g, b; static const Color Red, Green, Blue; }; constexpr Color Color::Red{255, 0, 0}, Color::Green{0,255,0}, Color::Blue{0, 0, 255}; [/cpp] If you want to restrict the range, do that in the constructor and throw an exception on failure (it will get caught at compile time if you make more constants like this). It may be even better to make the constructor private so you can only use the predefined colors if that's what you wish. You can add methods for manipulating the colors too. I suggest using int instead of something like uint8_t because you probably don't want overflowing/underflowing behavior to be defined (and with constexpr it'll get caught at compile time if you do over/under flow) and also you won't have to worry about signed/unsigned mismatches. On top of this, having an int will let you easily see if you went over your range by accident or on purpose and adjust accordingly. [editline]25th October 2017[/editline] [QUOTE=Karmah;52821283]Is it bad practice when writing your own libraries to split declarations and definitions between adjacent libraries? I'm trying to write a plugin system where I have a core library with some really generic objects, and other plugin libraries that link against core and provide the missing definitions. Sure I could just move the declarations into the plugin library, but it would be redundant and duplicate code because each plugin of that category would have the same declarations, just different definitions.[/QUOTE] Maybe I misunderstand but why can't you just make a header for the shared declarations and just use that between the libraries?
[QUOTE=WTF Nuke;52821539] Maybe I misunderstand but why can't you just make a header for the shared declarations and just use that between the libraries?[/QUOTE] This is essentially what I'm doing: [t]https://www.lucidchart.com/publicSegments/view/d974c475-e7f8-48cf-9ab2-8986fcd34c38/image.png[/t] Plugins [I]include[/I] the headers of the core library (as well as their .lib files) In the example above Class1::Bar() and Class2::Boo() are declared but undefined, and plugin implements 1 of those 2. Thus to get the full functionality a program would need to include all 3. However in this model Plugin1 could be swapped out with a new plugin like Plugin3 if it also reimplemented Class1::Bar() I guess what I'm trying to ask is whether or not it is unreasonable or unusual when working on libraries in this fashion to leave some functions undefined so that other libraries can complete them. I just try to do as much work ahead of time so that I can be lazy later. In this example, I try to keep as much of the declarations for 1 class as close together as they can be in the parent library, rather than have 2 functionally identical declarations in each of the child libraries.
[QUOTE=Karmah;52822162]This is essentially what I'm doing: [t]https://www.lucidchart.com/publicSegments/view/d974c475-e7f8-48cf-9ab2-8986fcd34c38/image.png[/t] Plugins [I]include[/I] the headers of the core library (as well as their .lib files) In the example above Class1::Bar() and Class2::Boo() are declared but undefined, and plugin implements 1 of those 2. Thus to get the full functionality a program would need to include all 3. However in this model Plugin1 could be swapped out with a new plugin like Plugin3 if it also reimplemented Class1::Bar() I guess what I'm trying to ask is whether or not it is unreasonable or unusual when working on libraries in this fashion to leave some functions undefined so that other libraries can complete them. I just try to do as much work ahead of time so that I can be lazy later. In this example, I try to keep as much of the declarations for 1 class as close together as they can be in the parent library, rather than have 2 functionally identical declarations in each of the child libraries.[/QUOTE] In your own projects I'd say do what the fuck you want but it sounds like a really really strange thing to do to me especially with the goal of making a plugin system,i can't see how that would give you anything.
[QUOTE=Karmah;52822162]This is essentially what I'm doing: [t]https://www.lucidchart.com/publicSegments/view/d974c475-e7f8-48cf-9ab2-8986fcd34c38/image.png[/t] Plugins [I]include[/I] the headers of the core library (as well as their .lib files) In the example above Class1::Bar() and Class2::Boo() are declared but undefined, and plugin implements 1 of those 2. Thus to get the full functionality a program would need to include all 3. However in this model Plugin1 could be swapped out with a new plugin like Plugin3 if it also reimplemented Class1::Bar() I guess what I'm trying to ask is whether or not it is unreasonable or unusual when working on libraries in this fashion to leave some functions undefined so that other libraries can complete them. I just try to do as much work ahead of time so that I can be lazy later. In this example, I try to keep as much of the declarations for 1 class as close together as they can be in the parent library, rather than have 2 functionally identical declarations in each of the child libraries.[/QUOTE] I suggest reading Gang of Four Design Patterns. I don't know what you are trying to accomplish but I'm sure it can be done more elegantly. But sure, when you leave such declarations undefined for the clients to define, then you are falling into "framework" territory - rather than "library". [editline]26th October 2017[/editline] [QUOTE=Karmah;52821283]Is it bad practice when writing your own libraries to split declarations and definitions between adjacent libraries? I'm trying to write a plugin system where I have a core library with some really generic objects, and other plugin libraries that link against core and provide the missing definitions. Sure I could just move the declarations into the plugin library, but it would be redundant and duplicate code because each plugin of that category would have the same declarations, just different definitions.[/QUOTE] Why not just use abstract classes in your main "library" and just extend those with your plugins? [editline]26th October 2017[/editline] Peeps, if C++ templates are required to be resolved for each data type usage in compile-time for error checking and stuff, then how dynamically-linked things, like standard library template classes can accept any arbitrary data-type? Is it all just YOLO undefined up-to-implementation? I was under impression that you need separate machine routines in your binary for each data-type, do you? I don't know, shit's confusing.
[QUOTE=DroppingPOCD;52823420] [editline]26th October 2017[/editline] Peeps, if C++ templates are required to be resolved for each data type usage in compile-time for error checking and stuff, then how dynamically-linked things, like standard library template classes can accept any arbitrary data-type? Is it all just YOLO undefined up-to-implementation? I was under impression that you need separate machine routines in your binary for each data-type, do you? I don't know, shit's confusing.[/QUOTE] Template parsing in C++ is an advanced as fuck concept, I hardly grok it. But things like that are why undefined behavior has sometimes been used as a feature in TMP shit. Anyways, recall that the code for unspecialized template classes is always defined 100% in a header - so it's not part of the runtime-loaded code that's inside a DLL. I mean, afaik. Maybe it is? Don't see how it would be. In many cases, the code generated for something like a std::vector<double>, a std::vector<int>, and a std::vector<unsigned char> will initially generate separate code that will then be reduced wherever there is common code for the various types (this happens loads with primitive types). That's mainly related to controlling binary bloat, though one of the things that can work across DLL boundaries is explicitly specialized template code. So, I imagine that if there are algorithms for like std::map<std::string> that are particularly efficient or optimal these could be defined and loaded from a DLL? I totally wandered off topic I think. My morning coffee slowly hit while I was writing this post.
Trying to use GLSL instead of the fixed pipeline in my game engine using SDL and OpenGL, the shader compiles successfully and works as expected when I specify OpenGL 3.1 or earlier [code]SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);[/code] but when I specify 3.2 or later [code]SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);[/code] the window is just black even though the shader still seems to compile successfully and there are no errors. I know that the fixed pipeline was completely deprecated in 3.2, but I am fairly certain that I got rid of any deprecated code. What did I do wrong?
Does your computer support 3.2? Like are you running a really old gpu or integrated graphics chip? What opengl profile is being set? You could still be using deprecated code + a strict no backwards-compatibility profile
[QUOTE=daigennki;52826989]Trying to use GLSL instead of the fixed pipeline in my game engine using SDL and OpenGL, the shader compiles successfully and works as expected when I specify OpenGL 3.1 or earlier [code]SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);[/code] but when I specify 3.2 or later [code]SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);[/code] the window is just black even though the shader still seems to compile successfully and there are no errors. I know that the fixed pipeline was completely deprecated in 3.2, but I am fairly certain that I got rid of any deprecated code. What did I do wrong?[/QUOTE] I saw your messages on steam as I was turning my computer off last night (Destiny is absorbing my life help) :V Debug the program in renderdoc: this will let you see what commands are even being submitted, if any.
Sorry, you need to Log In to post a reply to this thread.